Xmlvalidatingreader set schema
The Validation Type property determines the type of validation performed by the Xml Validating Reader.
You must set this property before calling the Read method.
For the uninformed, this holds the location of the Schema against which this document is to be validated.
And here’s the XML Schema against which the XML document listed above was originally built:[code]Validating file: Error: The element ‘book’ has invalid child element ‘inventory’. Validation Error: The ‘inventory’ element is not declared. Validation failed.[/code]This is followed by the definition of the object required for our example.
In such situations, you’ll also need to know how you can use a DTD to validate an XML document instance.
Here’s the updated XML file — notice it now includes a reference to a DTD instead of an XML Schema:[code][/code]A close look at this file and you will see that it describes the structure of the XML document instance fairly well.
The following table shows the rules for validation when the Validation Type property is set to DTD. Schema value is set, the Xml Validating Reader validates the document according to the XML Schemas, including inline schemas.
The following tables outline the values for the Validation Type property.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.Of course, in between all the element and attributes are quaint symbols and keywords that will make sense only to DTD experts (if you don’t belong to that elite group, you can start with the reference links provided at the end of this article). NET code that uses the [/code]It is interesting to note here that the XMLValidating Reader will continue to read the XML data even if it encounters an error – which is why it becomes critical to ensure that you devise your very own escape route to get out of erroneous situations.Now, you’ve already seen two of the three built-in objects based on the core Xml Reader object — the class allows you to read data from any node of a DOM tree present in memory.