Validating XML with XmlValidatingReader

The XmlValidatingReader provides DTD, XDR schema and XML Schema validation services by implementing the validity constraints defined by the W3C. The validation property, XmlValidatingReader.ValidationType, is set to the desired type of validation. Setting the property to None creates a W3C-compliant, non-validating parser. The XmlValidatingReader.ValidationType property is set to Auto by default.

The XmlValidatingReader takes an XmlTextReader as input. It also provides support for data-typed XML. This applies to attribute types defined in a DTD, as well as attribute and element types defined in an XDR schema or XML Schema (XSD). It also applies to instance level type information defined using XDR schema <dt:dt> and XML Schema <xsi:type> attributes. The validation of data type information is performed during parsing against an XDR schema or XML Schema or a DTD. If an external DTD or schema needs to be loaded, the resolver class provided as the XmlValidatingReader.XmlResolver Property is used to locate the external resource.

The XmlValidatingReader also provides a method to find out the data type of an object by using the XmlValidatingReader.ReadTypedValue method. The XmlValidatingReader.ReadTypedValue returns the contents of a simple type element or attribute as an object in the corresponding .NET Framework type. A simple type element or attribute is an element or attribute declared in the schema as a simple type, for example, as string or integer.

For more information on the XmlValidatingReader, performing validation, and using it with schemas, see Validation of XML with XmlValidatingReader. For more information about loading external DTDs and schemas and entity expansion using the XmlResolver, see Resolving Resources Using the XmlResolver.

See Also

Reading XML with the XmlReader | Reading XML Data with XmlTextReader | Reading Node Trees with XmlNodeReader | Customized XML Reader Creation | XmlReader Class | XmlReader Members | XmlNodeReader Class | XmlNodeReader Members | XmlTextReader Class | XmlTextReader Members | XmlValidatingReader Class | XmlValidatingReader