Reputation: 11
what is the best way to work with xml file that represets a tree. the xml size is 70mb.
Upvotes: 1
Views: 2214
Reputation: 120508
The answer depends on what you want to do with the XML. Generally with files that size you wouldn't want to read it all in one go. As such the following page makes an interesting read, providing a means to mine data from the file without loading it in memory. It allows you to combine the speed of XmlReader with the flexibility of Linq:
http://msdn.microsoft.com/en-us/library/bb387035.aspx
And quite an interesting article based on this technique:
Upvotes: 2
Reputation: 43
Since you are already using a DOM, an alternative XML parser you could try is a SAX parser. Instead of loading the entire tree into memory, a SAX parser is event-driven and handles nodes, etc. as it encounters them.
Further Reading: http://www.saxproject.org/event.html
Upvotes: 0
Reputation: 17014
Linq to XML is the easiest way to currently work with xml but this will typically load the entrire tree into memory which in your case with a 70mb file may not be ideal.
However there are ways around this as demonstrated in this blog post from Mick Taulty.
Upvotes: 2
Reputation: 11637
LinqToXml is probably a good bet if you wish to query it in memory, but if you find that you are getting problems with how large your memory footprint is you could use an XMLReader
Upvotes: 0
Reputation: 60724
For .NET 3.5 and up, I prefer using LINQ to XML for all my work towards XML files.
Upvotes: 0
Reputation: 9519
If you want to read data from a large xml file XmlTextReader
is the way to go.
Upvotes: 0