Best way to read a 1GB XML file with C#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

I have a 1GB XML file that I need to read once a day and I would like to get
feedback to find out what is the most efficient way to go about reading this
file. The application reading this is in C# and I am using .NET 2.0.

How can I read it without loading it all at once into memory? Will a simple
XmlDocument and a XmlNodeIterator work?

All feedback is extremely appreciated. Thanks!

Johnny
 
Johnny said:
Hello all,

I have a 1GB XML file that I need to read once a day and I would like to get
feedback to find out what is the most efficient way to go about reading this
file. The application reading this is in C# and I am using .NET 2.0.

How can I read it without loading it all at once into memory? Will a simple
XmlDocument and a XmlNodeIterator work?

All feedback is extremely appreciated. Thanks!

Johnny

You probably want to use the XmlReader and not load it all into a
document all at once ( although these days, you may have enough memory
to handle a file that large ). Still, I wouldn't do it.

Then you'd basically read it in node by node ( looking for the end node
) for the data your interested in, and store that as XmlNode, then use
it for whatever you want to do with it.
 
Using XmlDocument or XmlNodeDocument will parse the entire document upon
loading. For large documents you will need a non cached XmlReader, but you
still have to parse the document yourself.

You can consider generating and using an XmlNameTable to increase
performance:
Efficient Techniques for Modifying Large XML Files
By Dare Obasanjo
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/largexml.asp

Object Comparison Using XmlNameTable with XmlReader
http://msdn.microsoft.com/library/d...tComparisonUsingXmlNameTableWithXmlReader.asp

ok,
aq
 
Back
Top