2

如何将一个 XML 文档中的 XML 节点替换为另一个 XML 文档中的另一个 XML 节点。请帮忙..

4

1 回答 1

4

您可以使用 LINQ to XmlXElement.ReplaceWith方法

// 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);
于 2012-12-07T12:10:57.100 回答