Import XML Nodes from differnet XmlDocuments

Everytime I see a developer coming from Visual Basic or Javascript doing some XML developemnt I get a question: How do I import a XmlNode from a different XmlDocument?

Here is the short answer:

XmlDocument newXml = new XmlDocument();
XmlDocument oldXml = new XmlDocument();
...
XmlNode oldNode = oldXml.DocumentElement.ChildNodes[0];  // f.e.

XmlNode importXml = newXml.ImportNode(oldNode, true);
newXml.DocumentElement.AppendChild(importXml);

1 Comment

Comments have been disabled for this content.