Merging two xml files in C# without appending and without deleting anything (example given)

后端 未结 3 627
野的像风
野的像风 2021-01-23 07:55

So say I have one xml file such as this:


    shape1

And another xml file like this:

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 08:19

    You can load both files into two XElement objects, locate the target nodes in both objects and add or remove as you wish.

    Here is a sample:

    var doc1 = XDocument.Parse(file1).Element("shapes");
    var doc2 = XDocument.Parse(file2).Element("parentNode").Element("shapes");
    
    doc2.Add(doc1.Nodes());
    

提交回复
热议问题