How to merge two XmlDocuments in C#

后端 未结 4 870
半阙折子戏
半阙折子戏 2020-12-14 17:33

I want to merge two XmlDocuments by inserting a second XML doc to the end of an existing Xmldocument in C#. How is this done?

4条回答
  •  [愿得一人]
    2020-12-14 17:51

    This is the fastest cleanest way to merge xml documents.

    XElement xFileRoot = XElement.Load(file1.xml);
    XElement xFileChild = XElement.Load(file2.xml);
    xFileRoot.Add(xFileChild);
    xFileRoot.Save(file1.xml);
    

提交回复
热议问题