如何在不加载在内存中的整个文件更新XML文件文件、加载、内存、如何在

由网友(这一幕太刺眼°)分享简介:如何在不完全加载到内存中,我们可以更新XML文件。在下面的code我想浏览每个父节点说明和更新的值到节点。我们如何才能做到这一点使用C#。我必须更新基于一些其他的计算,我在code到现场。<注意><从>贾尼< /从>&所述;至大于托弗&所述; /到大于< /笔记>...

如何在不完全加载到内存中,我们可以更新XML文件。在下面的code我想浏览每个父节点说明和更新的值到节点。我们如何才能做到这一点使用C#。我必须更新基于一些其他的计算,我在code到现场。

 <注意>
<从>贾尼< /从>
&所述;至大于托弗&所述; /到大于
< /笔记>
<注>
<从>约翰< /从>
&所述;至大于Doe的所述; /到大于
< /笔记>
 

解决方案

您可以使用流媒体的方式与的XmlReader 的XmlWriter ,在那里你只需写出一切从读者除了你需要改变。

部分

斯科特Hanselman有一个博客发布使用这种技术。

教程 在Excel工作表中加载XML文件的方法

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.

阅读全文

相关推荐

最新文章