How do I read a 250 Meg XML file?

Ok.  A vendor is giving me a 250 Meg XML file.  I am having a very difficult time reading this, because of the size.  I keep getting memory errors in my application.  Here is the basic code I am using to read this.  I am sure that the xmlDoc.Load is reading the entire document into memory.  What I need, is to read it a I go, not all at once.  I can't figure out an Xml way of doing it.  The only way I can think of to make this work, is to read the Xml file, as if it were a text file, one record at a time, and manually process the Xml.  There has to be a better way, isn't there

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);
XmlNode DataNode = xmlDoc.FirstChild;
DataNode = DataNode.NextSibling;
DataNode = DataNode.FirstChild;
DataNode = DataNode.FirstChild;
while(DataNode != null)
{
   .
   .
   .
   .
   DataNode = DataNode.NextSibling;
}



Answer this question

How do I read a 250 Meg XML file?

  • nimayb

    What happened to SAX   I can't find it anywhere in the XML namespace.... is the XMLReader the replacement for it


  • Zueriva

    System.Xml.XmlReader class is exactly what you need. See "Reading XML with the XmlReader" at http://msdn2.microsoft.com/library/9d83k261(en-us,vs.80).aspx

  • JamesB43_

    Yep, XmlReader is a complete replacement for SAX in .NET. The same low-level streaming non caching XML parser, but pull-mode hence easier to work with.

  • VenkataS

    Hi,

    did you try the Dataset class with dataset.readxml and dataset.writexml

  • How do I read a 250 Meg XML file?