如何在 C# 中解析非常大的 XML 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15772031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to parse very huge XML Files in C#?
提问by Bilal Ahmed Yaseen
I am working with dblp XML files. I actually want to parse the dblp.xml file and want to extract the usefull information for my further processing in some project. And that XML File is very huge (1.1 GB) and I am unable to even open this file.
我正在处理 dblp XML 文件。我实际上想解析 dblp.xml 文件,并想提取有用的信息,以便在某个项目中进一步处理。而且那个 XML 文件非常大(1.1 GB),我什至无法打开这个文件。
Kindly guide me if you have C# parser for dblp.xml or you can guide me regarding this, or about how can we parse huge xml files.
如果您有 dblp.xml 的 C# 解析器,请指导我,或者您可以就此指导我,或者我们如何解析巨大的 xml 文件。
采纳答案by Gergo Szekeres
Use XML reader instead of XML dom. XML dom stores the whole file in memory which is totally useless:
使用 XML 阅读器而不是 XML dom。XML dom 将整个文件存储在内存中,这是完全没用的:
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx
http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx
回答by illegal-immigrant
You need to use XmlReader
你需要使用 XmlReader
It represents a reader that provides fast, noncached, forward-only access to XML
data. Won't load all the data into memory, supposed to be used with large sets of data. Other built in.NET
solutions keep the full generated object graph.
它代表一个读取器,它提供对XML
数据的快速、非缓存、只进访问。不会将所有数据加载到内存中,应该与大量数据一起使用。其他内置.NET
解决方案保留完整生成的对象图。