Elad
Elad

Reputation: 11

What is the best way to work with xml?

what is the best way to work with xml file that represets a tree. the xml size is 70mb.

Upvotes: 1

Views: 2214

Answers (6)

spender
spender

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:

Link

Upvotes: 2

matt.schechtman
matt.schechtman

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

Andy Rose
Andy Rose

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

Pondidum
Pondidum

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

Linq To XML

  • Slower for larger documents (large memory footprint)
  • Queryable

XmlTextReader

  • Fast
  • Only one line at a time, so no querying

Upvotes: 0

Øyvind Bråthen
Øyvind Bråthen

Reputation: 60724

For .NET 3.5 and up, I prefer using LINQ to XML for all my work towards XML files.

Upvotes: 0

Stefan P.
Stefan P.

Reputation: 9519

If you want to read data from a large xml file XmlTextReader is the way to go.

Upvotes: 0

Related Questions