开发者

How to Update an xml file without loading the entire file in memory

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜