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 に答える