XmlTextReader的主场迎战的XDocument [英] XmlTextReader vs. XDocument

查看:192
本文介绍了XmlTextReader的主场迎战的XDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解析XML在.NET中的地位。现在我之间至少有的XmlTextReader 的XDocument 的选择。是否有这两个之间的比较(或包含在框架中任何其他的XML解析器)?

I'm in the position to parse XML in .NET. Now I have the choice between at least XmlTextReader and XDocument. Are there any comparisons between those two (or any other XML parsers contained in the framework)?

也许这可以帮助我没有深入的尝试他们都来决定。

Maybe this could help me to decide without trying both of them in depth.

中的XML文件预计将相当小,速度和内存使用是一个小问题相比,使用容易。 : - )

The XML files are expected to be rather small, speed and memory usage are a minor issue compared to easiness of use. :-)

(我打算使用它们从C#和/或IronPython的。)

(I'm going to use them from C# and/or IronPython.)

谢谢!

推荐答案

如果你感到快乐阅读一切到内存中,使用的XDocument 。它会让你的生活的的更容易。的LINQ to XML是一种的可爱的API。

If you're happy reading everything into memory, use XDocument. It'll make your life much easier. LINQ to XML is a lovely API.

使用的的XmlReader (如的XmlTextReader )如果你需要处理的巨大的以流传输方式的XML文件,基本上。这是一个更痛苦的API,但它允许数据流(即只具有数据处理,因为你需要它,所以你可以通过一个巨大的文件,只有在一个时间少量的内存)。

Use an XmlReader (such as XmlTextReader) if you need to handle huge XML files in a streaming fashion, basically. It's a much more painful API, but it allows streaming (i.e. only dealing with data as you need it, so you can go through a huge document and only have a small amount in memory at a time).

有一个混合的方法,但是 - 如果你有由小单元一个巨大的文件,你可以创建一个的XElement 的XmlReader 定位在元素的起点,应对使用LINQ to XML中的元素,然后将的XmlReader 到下一个元素,并重新开始。

There's a hybrid approach, however - if you have a huge document made up of small elements, you can create an XElement from an XmlReader positioned at the start of the element, deal with the element using LINQ to XML, then move the XmlReader onto the next element and start again.

这篇关于XmlTextReader的主场迎战的XDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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