XML Processing With The XMLReader Object, Part 2
(Page 1 of 6 )
This concluding segment discusses XML validation with the XmlValidatingReader class using both DTDs and XML Schemas, introduces the XMLNodeReader, and shows you how to add exception-handling to your XML processing code. If you wish to catch up, check out the
first article in this series.
Onward Ho
You already know that an XML document may be either "well-formed" or "valid."
A well-formed document is one which meets the specifications laid down in the XML recommendation; that is, it follows the rules for element and attribute names, contains all essential declarations, and has properly-nested elements.
A valid document is one which, in addition to being well-formed, adheres to the rules laid out in a document type definition (DTD) or XML Schema. By imposing some structure on an XML document, a DTD makes it possible for documents to conform to some standard rules, and for applications to avoid nasty surprises in the form of incompatible or invalid data.
DTDs and XML Schemas are essential when managing a large number of XML documents, as they immediately make it possible to apply a standard set of rules to different documents and thereby demand conformance to a common standard. However, for smaller, simpler documents, a DTD can often be overkill, adding substantially to download and processing time.
Now, what does this have to do with the XmlTextReader class I discussed in so much detail in the last segment of this previous tutorial? Nothing, really. You see, while the class does throw up errors if your XML document isn't well-formed, it does not support validation against a DTD, XDR or XSD Schema. If you need to validate your XML file before processing it, you need to know its close cousin, the XmlValidatingReader object, which is derived from the same abstract XMLReader parent class. And then, once you know how to perform validation, you also need to know how to handle validation errors, which is why this article also includes a simple example that uses built-in exception handling mechanisms to trap errors that the Reader may come across.
Let's get started!
Next: Returning to the Library >>
More XML Articles
More By Harish Kamath (c) Melonfire