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

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

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


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


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

    Using string-based techniques (like seeking to the end of the file and then moving backwards the length of the closing tag) is vulnerable to unexpected but perfectly legal variations in document structure.

    The document could end with any amount of whitespace, to pick the likeliest problem you'll encounter. It could also end with any number of comments or processing instructions. And what happens if the top-level element isn't named Error?

    And here's a situation that using string manipulation fails utterly to detect:

    
       ...
    
    

    If you use an XmlReader to process the XML, while it may not be as fast as seeking to EOF, it will also allow you to handle all of these possible exception conditions.

提交回复
热议问题