tags:

views:

1841

answers:

3

What is the fastest method of parsing an XML file in C#? I'm using .Net 2.0

+6  A: 

If you're using .Net 2 then the XmlReader and XmlDocument are about it.

If you can use .Net 3.5 then the new Linq to Xml methods are a big improvement.

Keith
A: 

I haven't benched-marked it myself, but when I've asked about it in the past I've been told that XmlDocument is supposed to be faster. I have my doubts, though, since XmlDocument would need to create a DOM while XmlReader does not.

Joel Coehoorn
+1  A: 

If you use an XmlTextReader class it will technically be faster than using an XmlDocument, which parses the entire file and builds a DOM for you. But you must also consider that fact that with an XmlTextReader, you are just reading one node at a time, so there is the additional overhead of making sense of the data as you read it. If you are going to end up storing everything yourself anyway, using XmlDocument might end up being more efficient.

Eric Z Beard