修改就地XML文件? [英] Modifying XML file in-place?

查看:98
本文介绍了修改就地XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有下面的XML文件:

Suppose I have the following XML File:

<book>
 <name>sometext</name>
 <name>sometext</name>
 <name>sometext</name>
 <name>Dometext</name>
 <name>sometext</name>
</book> 

如果我想通过改变D钮S(正如在第四个名显示修改内容节点),而无需读/写整个文件,这会是可能的吗?

If I wanted to modify the content by changing D to s (As shown in the fourth "name" node) without having to read/write the entire file, would this be possible?

推荐答案

一个10 MB的文件是不是有问题。嘟嘟地喝起来。修改DOM。把它写回文件系统。 10 GB是更大的问题。在这种情况下:

A 10 MB file is not a problem. Slurp it up. Modify the DOM. Write it back to the filesystem. 10 GB is more of a problem. In that case:

假设:您不改变文件的长度。认为该文件作为字符数组和字符不是(链接)名单:你不能在中间添加字符,只能改变他们

Assumption: You are not changing the length of the file. Think of the file as an array of characters and not a (linked) list of characters: You cannot add characters in the middle, only change them.

您需要征求在文件中的位置来改变再该字符到磁盘。

You need to seek the position in the file to change and then write that character to disk.

在.NET世界,用的FileStream 对象,你怎么设置位置属性在 D的指数字符,然后编写一个取值字符。 检查出的文本文件随机访问<这个问题/一>。

In the .NET world, with a FileStream object, you what to set the Position attribute to the index of the D character and then write a single s character. Check out this question on random access of text files.

另请阅读这个问题:的如何插入字符使用C#的文件。它看起来像你真的不能使用的FileStream 对象,而是将不得不诉诸写入单个字节。

Also read this question: How to insert characters to a file using C#. It looks like you can't really use the FileStream object, but instead will have to resort to writing individual bytes.

祝你好运。但实际上,如果我们只谈论10 MB,那么就嘟嘟地喝起来。计算机应该做的工作。

Good luck. But really, if we are only talking 10 MB, then just slurp it up. The computer should be doing your work.

这篇关于修改就地XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆