Reputation: 51
How replace XML Node from one XML document with another XML node from another XML Document. Please help..
Upvotes: 2
Views: 3961
Reputation: 236188
You can use LINQ to Xml XElement.ReplaceWith
method
// select node from one doc
XDocument xdoc1 = XDocument.Load(path_to_doc1);
XElement one = xdoc1.Descendants("One").First();
// select node from another doc
XDocument xdoc2 = XDocument.Load(path_to_doc2);
XElement another = xdoc2.Descendants("Another").First();
// replace one xml node with another
one.ReplaceWith(another);
xdoc1.Save(path_to_doc1);
Upvotes: 4