如何在不将其加载到内存中并使用 XElement 的情况下读取大型 xml 文件 [英] How to read large xml file without loading it in memory and using XElement

查看:23
本文介绍了如何在不将其加载到内存中并使用 XElement 的情况下读取大型 xml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取一个大的 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 与 方法 XNode.ReadFrom,参见文档中的示例,该示例使用 C# 将 XmlReader 发现的节点选择性地处理为 XElement.

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.

这篇关于如何在不将其加载到内存中并使用 XElement 的情况下读取大型 xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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