Performance: XDocument versus XmlDocument

前端 未结 2 726
庸人自扰
庸人自扰 2020-12-03 13:58

I have read a comparison between the two here. This is primarily a question of performance, relating to both memory and speed.

I\'ve got several XML documents that a

相关标签:
2条回答
  • 2020-12-03 14:25

    XmlReader is the lowest API in .NET which all other XML APIs in .NET use under the scenes. Naturally that means it's the hardest to deal with, as well as fastest. It's a streaming API, so it is best fit for memory as well.

    Between XmlDocument and XDocument aka Linq to XML, here are some raw numbers: http://blogs.msdn.com/b/codejunkie/archive/2008/10/08/xmldocument-vs-xelement-performance.aspx

    Both of which find XDocument class being faster/more efficient. Programmer productivity/efficiency shouldn't be ignored as well. Personally I find it easier to work with XDocument.

    0 讨论(0)
  • 2020-12-03 14:44

    XmlDocument is a purely managed implemenation of the Document Object Model. There is no interop with any COM components, such as the MSXML library. Any claim otherwise is completely bogus. The entire XLinq set of APIs came about as a friendlier way to interact with XML with introduction of LINQ in the .NET Framework.

    If you're trying to maximize performance and are comfortable using XPath, try using the XmlDocument and using compiled XPath expressions.

    0 讨论(0)
提交回复
热议问题