这是最好的性能明智的:XPathNavigator的使用XPath VS的LINQ to XML与查询? [英] Which is the best for performance wise: XPathNavigator with XPath vs Linq to Xml with query?

查看:139
本文介绍了这是最好的性能明智的:XPathNavigator的使用XPath VS的LINQ to XML与查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我使用的XPathNavigator遍历节点的应用程序。这是工作的罚款。

I have an application in which I am using XPathNavigator to iterate nodes. It is working fine.

但我想知道,如果我使用LINQ到XML ....

But I want to know that if I use LINQ to Xml....

  1. 什么好处(性能,可维护性),我会得到什么?

  1. What benefits(Performance, maintainability) I will get?

在XPath,LINQ到XML这是对性能的影响?

With XPath, LINQ to Xml what is the performance hit?

我使用C#.NET,Visual Studio 2010和我的.xml是中等大小。

I am using C#.net, VS 2010 and my .xml is mid size.

推荐答案

嗯,的XPathNavigator 通常比的LINQ更快的XML 查询。但是,总有但是。

Well, XPathNavigator will generally be faster than Linq to XML queries. But there's always 'but'.

的LINQ to XML 一定会令您code的可读性和可维护性。它更容易(至少对我来说)来读取LINQ查询然后分析的XPath。此外 - 你会写的查询,这将有助于使你的code正确的,当获得智能。 的LINQ to XML 还为您提供了可能性,很容易地修改数据,如果这就是你所需要的。 的XPathNavigator 为您提供了只读访问。

Linq to XML will definitely make your code more readable and maintainable. It's easier (at least for me) to read linq query then analyze XPath. Also - you will get intellisense when writing query which will help to make your code correct. Linq to XML also gives you possibility to easily modify data, if that's what you need. XPathNavigator gives you readonly access.

在另一方面,如果你真的需要顶级的性能,的XPathNavigator 可能是要走的路。它只是取决于你目前的情况和你所要完成什么。如果性能是不是一个问题(XML文件是相当小的,你会不会让许多请求这个文件等),您可以轻松地与的LINQ到XML 。否则,贴地的XPathNavigator

On the other hand, if you really need top performance, XPathNavigator is probably the way to go. It simply depends on your current scenario and what you're trying to accomplish. If performance is not an issue (XML file is rather small, you won't make many requests to this file and so on) you can easily go with Linq to XML. Otherwise stick close to XPathNavigator.

这篇关于这是最好的性能明智的:XPathNavigator的使用XPath VS的LINQ to XML与查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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