What is the most efficient why to read XML files?
In my last code review, which has made by shani raba, he have write me down a comment about the way that I read data from XML file, which is with the help of XmlDocument. And his point was that that way it is much slower then with, lets say, XmlReader.
So I have googled and came up with those conclusions. Using a XmlDocument for reading XML files is really a bit slower then using XmlRaeder. Although if you need also to write into the XML this would be the prepared option.
The XmlReader work 2-3 times faster then the XmlDocument because it doesn't save state of the document and the pointer on then file can be moved only forward. I say keep that idea aside for rainy day when you have to work with 10M XML files with thousands of elements. For now if you need to handle much smaller XML files then I suggest to use XmlDocument, even if you want only to read data. The overhead is negligible and only think about the benefits that you get. You have one object, which by my opinion is really easy to use, that can handle what ever you think of with XML files. And more importantly you keep on really strict standard for all your code. I think this is worth the price that you pay doesn’t it?
So I recommend using XmlDocument for managing your XML files in 90% of the time.
There are more objects that you can use to handle XML files.
You can find here some comparing between all of them.