XML Processing with the XMLReader Object, Part 1 - Class Act
(Page 2 of 5 )
The XMLReader abstract class plays a very important role in implementing the new "pull model." As part of the System.XML tree, the primary objective of this class is to provide developers with a framework to implement this new model. If you're an adventurous developer, you can use this abstract class as the basis for your very own, custom-crafted XMLReader object. Or you could do what I did: take the easy way out and utilize any one of the built-in classes that already do this for you.
The .NET framework provides three such built-in classes:
1. The plain-vanilla XmlTextReader class behaves as a "forward-only, noncached reader" to read XML data. It's versatile enough to allow you to access XML from different input sources, including flat files, data streams, or URLs.
2. The XmlTextReader has one little drawback: it doesn't allow you to validate the data present in the XML source. If you are looking for a foolproof way to maintain the sanctity of your data, you are better off using the XmlValidatingReader class. This is the only class in this category that comes with built-in features to validate your XML data against external DTDs, XDR or XSD schemas.
3. In case you're looking to implement the "pull model" on a DOM tree that's already present in memory, you can consider using the XmlNodeReader class. Best-suited only for the very specialized application mentioned above, this class allows you read the data from specific nodes of the tree and enjoy a double benefit: the speed associated with the XMLReader class and the ease of use of the DOM.
Now that you know the theory, how about seeing it work in the real world?
Next: Visiting the Library >>
More XML Articles
More By Harish Kamath (c) Melonfire