The Xml Validating Reader class is an implementation of the Xml Reader class that provides support for several types of XML validation: Document Type Definitions (DTD), XML-Data Reduced (XDR) schemas, and XML Schemas (XSD).
You can use the Xml Validating Reader class to validate entire XML documents as well as XML fragments.
To validate an entire XML document you just loop through its content, as shown in the code below: Notice that the reader's internal mechanisms responsible for checking the document's well-formedness and schema compliance are distinct.
So if a validating reader happens to work on a badly-formed XML document, no event is fired but an Xml Exception exception is raised.
If the validation is successful, a message to that effect is displayed.
If there is a validation error, or an exception is thrown, the relevant information is displayed to the user.
Typically, a warning is raised when there is no DTD, XDR or XSD schema to validate a particular element or attribute against.
An XML validating reader, in fact, cannot be directly initialized from a file.
Error indicates that a serious validation error occurred when processing the document against a DTD, XDR or a XSD schema.
If the current instance of the Xml Validating Reader class has no validation event handler set, then an exception is thrown.
Although the Xml Validating Reader class inherits from the base class Xml Reader, it really implements internally only a very small set of all the required functionalities.
Because the class works on top of an existing XML reader, many methods and properties are just mirrored.
The Exception field, instead, returns an ad-hoc exception object (Xml Schema Exception) with details about what happened.