How can we update an xml file without loading it entirely into memory. In the following code I want to navigate through each parent开发者_运维百科 node note and update the value of the to node. How can we achieve this using C#. I have to update the to field based on some other calculation that I have in code.
<note>
<from>Jani</from>
<to>Tove</to>
</note>
<note>
<from>John</from>
<to>Doe</to>
</note>
You can use a streaming approach with XmlReader
and XmlWriter
, where you simply write out everything from the reader apart from the portions you need to change.
Scott Hanselman has a blog post using this technique.
you can use XmlReader and XmlWriter. here are some examples.
http://dotnetperls.com/xmlreader, http://dotnetperls.com/xmlwriter
精彩评论