Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Moving Nodes From One XmlDocument To Another

DZone's Guide to

Moving Nodes From One XmlDocument To Another

·
Free Resource
In .NET has some powerful tools to deal with Xml. All Xml nodes need to be created in the context of a XmlDocument object. If you need to move the nodes from one Xml Document to another, it's not obvious that you can just copy the nodes from one XmlDocument to another, after all Xml is just text isn't it.

Here's how to move all the nodes from one Xml Document to another:


// Dont forget this one:
using System.Xml;

// First, get some documents together
XmlDocument DocumentSource = new XmlDocument();
XmlDocument DocumentDestination = new XmlDocument();

// Load the documents with some nodes
DocumentSource.LoadXml("");
DocumentDestination.LoadXml("");

// Now to do the conversion
XmlNode tempNode = DocumentDestination.ImportNode( DocumentSource.FirstChild )

// Now insert the fragment into the document
DocumentDestination.FirsChild.AppendChild(tempNode);
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}