By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,017 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,017 IT Pros & Developers. It's quick & easy.

create xml element

P: n/a

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!
Mar 22 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a

Ryan Liu wrote:

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

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>";


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



Martin Honnen --- MVP XML
Mar 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.