将大型 xml 文件拆分为子文件而不会出现内存争用 [英] Splitting large xml files in to sub files without memory contention
本文介绍了将大型 xml 文件拆分为子文件而不会出现内存争用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像下面这样的 XML
I have a XML like following
<Jobs>
<job>
....
</job>
<job>
....
</job>
....
</Jobs>
现在最好的方法是将每个作业节点写入一个单独的文件而不带整个使用 xmlreader 和 xmlwriter 或任何其他选项将文件写入内存?
Now what is best way to write each job node in a separate file without bringing the whole file in to memory using xmlreader and xmlwriter or anyother options?
推荐答案
- 为输入文件创建一个 XmlReader.
- 将读者定位在第一个工作元素上.
- 使用 ReadSubtree 方法创建子树 XmlReader一>.
- 为输出文件创建一个 XmlWriter.
- 使用 WriteNode 方法 将子树 XmlReader 的内容复制到 XmlWriter一>.
- 将原始阅读器放在下一个作业元素上,继续第一个作业元素.
如果没有更多工作元素可供阅读,则中断.
- Create an XmlReader for the input file.
- Position the reader on the first job element.
- Create a subtree XmlReader using the ReadSubtree Method.
- Create an XmlWriter for the output file.
- Copy the contents of the subtree XmlReader into the XmlWriter using the WriteNode Method.
- Position the original reader on the next job element, continue as with the first job element.
Break if there are no more job elements to read.
这篇关于将大型 xml 文件拆分为子文件而不会出现内存争用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文