I have a large xml file (approx. 10 MB) in following simple structure:
<Errors>
<Error>.......</Error>
<Error>.......</Error>
<Error>.......</Error>
<Error>.......</Error>
<Error>.......</Error>
</Errors>
My need is to write add a new node <Error> at the end before the </Errors> tag. Whats is the fastest way to achieve this in .net?
You need to use the XML inclusion technique.
Your error.xml (doesn’t change, just a stub. Used by XML parsers to read):
Your errorrows.txt file (changes, the xml parser doesn’t understand it):
Then, to add an entry to errorrows.txt:
Or you can even use .NET 3.5 XElement, and append the text to the
StreamWriter:See also Microsoft’s article Efficient Techniques for Modifying Large XML Files