473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

create xml element

Hi,

I know I need create a DataRow from a DataTable for the schema reason.

Why must I create a XmlElement in a XmlDocument?

I already have a string, I was trying to use XmlDocument.CreateElement("Q")
method to create a "fake" or "Empty" XmlElement and set this element's
OuterXml, but OuterXml is read only.

I can set inner Xml, but I think I will lost attributs of element Q. I will
try that out.

But what is best practice to create an element from a given complete node
string? Should I try ImportNode()?

And same as new DataRow does not belong to DataTable, after I create the
element, it is not part of the XmlDocument unless I append to one of its
chile node, right?

Microsoft SDK is great resouce, but some time I still feel it tells
something, but not deep and clear enough, I need write small test programs
and ask others to know what really is its accurate meaning.

Thanks a lot!
Ryan
Mar 22 '06 #1
1 2926


Ryan Liu wrote:

But what is best practice to create an element from a given complete node
string?


You can use a DocumentFragment node and set its InnerXml property e.g.

XmlDocument xmlDocument = new XmlDocument();
// load some example contents
xmlDocument.LoadXml(@"<gods />");

XmlDocumentFragment fragment = xmlDocument.CreateDocumentFragment();
fragment.InnerXml = @"<god>Kibo</god><god>Xibo</god>";
xmlDocument.DocumentElement.AppendChild(fragment);

xmlDocument.Save(Console.Out);

And there is the ReadNode method e.g.

XmlDocument xmlDocument = new XmlDocument();
// some example contents
xmlDocument.LoadXml(@"<gods />");

XmlNode node = xmlDocument.ReadNode(new XmlTextReader(new
StringReader(@"<god>Kibo</god>")));
xmlDocument.DocumentElement.AppendChild(node);

xmlDocument.Save(Console.Out);

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: takarimasu | last post by:
How can i create an input object (text area,select) at runtime ? B.
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
3
by: Dhananjayan | last post by:
Hi, I have a java webservice running on Axis, Iam able to create a java client to invoke the webservice and obtain the result. But iam not able to invoke the service from .Net client.. Here are...
0
by: DotDidIt | last post by:
Hi Everybody! I developed a Web service with IBM RAD v 6.0.1. After creating the WSDL file i have tried to develop a .Net client. But by using wsdl.exe (1.1.4322) to create a .net c# proxy i...
4
by: Ganesh Muthuvelu | last post by:
Hello, Let us say that I have a schema or complex type like this one below: Is there a way programtically or a tool to create sample XML file/data for the schema?. I have number of such complex...
4
by: Dmitry Kulinich | last post by:
Guys! Is there are any possibility to create nodes with duplicate names and different types in XSD? I've read the whole specification and tried in a many different ways, but not successfull. ...
13
by: Bill Nguyen | last post by:
Is it possible to create your won XSD to use with .NET based on an XML content? For example the one below: <?xml version="1.0"?> <pcats:FuelsDoc...
14
RMWChaos
by: RMWChaos | last post by:
Firebug is reporting "too much recursion" when I attempt to create a child element in a parent that doesn't exist yet. The script should automatically create the missing parent before going on to...
2
markmcgookin
by: markmcgookin | last post by:
Hi Folks, Bear with me if this sounds stupid pls! I have an xsl doc that is translating one type of xml to another (still with me?) I was wondering, is it possible to do the same thing to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.