XMLDomDoc vs XMLTextReader

  • Thread starter Thread starter MFRASER
  • Start date Start date
M

MFRASER

I am trying to import some data into my objects and I have been using
XMLDoc.LoadXML(file), but someone told me that this is very memory intensive
that if I am reading a text file that I would be better off using
XMLTextReader. Has anyone had the same experience?
 
That is true. The XmlDocument must load the entire XML structure in memory
and construct a tree. My unofficial guess is that the memory footprint is
probably exponential when given larger documents.

The XmlTextReader only processes what it has to and does not maintain a tree
structure. The XmlDocument allows you to go anywhere and to anything, the
XmlTextReader is forward-only and cannot be modified.

If you are only reading the document, and you know the structure, then an
XmlTextReader would be more efficient.

It is really a judgement call as to what you use.
 
Michael,

You cannot perform XPath queries against an XMLTextReader because
the object doesn't keep a tree in memory which represents the data.
XMLTextReader is sort of like a "firehose" cursor: it has a current
position, and while you're reading in the document, you can find out
the type of the current node (is it an element, a comment, an
attribute, etc.), but if you don't do something to store the data as
its read it all evaporates when the Read() method returns false at the
end of the file.

You can see an example of the XMLTextReader in action here:

http://www.xmlforasp.net/codebank/u...TextReader.src&file=XmlTextReader.aspx&font=3

Good luck,
Les Matheson
Integral Concepts, Inc.
http://www.ivsds.com
 
Back
Top