如何读取大型xml文件而不将其加载到内存中并使用XElement

如何读取大型xml文件而不将其加载到内存中并使用XElement

问题描述:

我想读取一个较大的xml文件(100 + M).由于其大小,我不想使用XElement将其加载到内存中.我正在使用linq-xml查询来解析和读取它.

I want to read a large xml file (100+M). Due to its size, I do not want to load it in memory using XElement. I am using linq-xml queries to parse and read it.

最好的方法是什么? XPath或XmlReader与linq-xml/XElement结合的任何示例吗?

What's the best way to do it? Any example on combination of XPath or XmlReader with linq-xml/XElement?

请帮助.谢谢.

是的,您可以将XmlReader与

Yes, you can combine XmlReader with the method XNode.ReadFrom, see the example in the documentation which uses C# to selectively process nodes found by the XmlReader as an XElement.