What is the fastest way to combine two xml files into one

后端 未结 11 1548
广开言路
广开言路 2020-11-29 01:43

If I have two string of xml1 and xml2 which both represent xml in the same format. What is the fastest way to combine these together? The format is not important, but I ju

11条回答
  •  -上瘾入骨i
    2020-11-29 02:00

    In my case the main solution did not work well, the difference was that I had a List for a thousands of files when I take one element and try to merge with the first element I get OutOfMemory exception, I added an empty template with and empty row (NodeA in this case) to solve the weird problem of the memory and run smoothly.

    I save the document in other process

    XDocument xmlDocTemplate = GetXMLTemplate(); -- create an empty document with the same root and empty row element (NodeA), everything will be merge here.
    List lstxElements = GetMyBunchOfXML();
    
    foreach (var xmlElement lstxElements)
    {
        xmlDocTemplate
            .Root
            .Descendants("NodeA")
            .LastOrDefault()
            .AddAfterSelf(xmlElement.Descendants("NodeA"));
    }
    

提交回复
热议问题