Linq to XML vs DOM

In one of the applications we are developing, we process a lot of XML. We currently use DOM and XPath for most of the processing, and we are not very pleased with the performance.

We are currently considering moving the XML processing logic to LINQ, and our initial research shows that LINQ performance is much better than the DOM.

Before embarking on these changes, I would like to know how others relate to this. Does LINQ use the best option? Any flaws, etc.

Thanks, Shamika


Thanks so much for your answers. I performed some performance tests and, as expected, XmlReader performed both XmlDocument and LINQ. Please note that this is read-only XML.

In addition, if you need the ease of use of LINQ, you can implement LINQ XML processing with some XmlReader functions and get much better performance than XmlDocument. Please refer to the "rwwilden" comments for more information.

Thanks.

+5
source share
3 answers

Using the DOM (i.e. System.Xml.XmlDocument) is likely to be slower due to the rich navigation support (all of these links start with add up), and this overhead will become more significant as the number of nodes increases.

(System.Xml.Linq.XDocument System.Xml.XPath.XPathDocument) , . , .

( ) , , ( ) .

: System.Xml.XmlReader System.Xml.XmlWriter . , .

.NET (, ) XML-API, (, , ) , , .

XmlDocument XPathDocument ( XPath), XDocument ( ), XmlReader/XmlWriter , .

+3

, , LINQ2XML DOM/XPath. DOM, LINQ2XML , , .

, XML, XML, ( XStreamingElement). Microsoft XML .

+2

, LINQ → XML , DOM. IMO.

+1

All Articles