Fastest way to add new node to end of an xml?

前端 未结 10 702
深忆病人
深忆病人 2020-11-29 10:21

I have a large xml file (approx. 10 MB) in following simple structure:


   .......
   .......         


        
10条回答
  •  青春惊慌失措
    2020-11-29 11:02

    The quickest method is likely to be reading in the file using an XmlReader, and simply replicating each read node to a new stream using XmlWriter When you get to the point at which you encounter the closing tag, then you just need to output your additional element before coninuing the 'read and duplicate' cycle. This way is inevitably going to be harder than than reading the entire document into the DOM (XmlDocument class), but for large XML files, much quicker. Admittedly, using StreamReader/StreamWriter would be somewhat faster still, but pretty horrible to work with in code.

提交回复
热议问题