Validation of XML with XmlValidatingReader

The XmlValidatingReader class, an implementation of the XmlReader class, provides support for XML validation. You can use the XmlValidatingReader to validate XML documents and XML fragments. This class implements the validity constraints defined in the World Wide Web Consortium (W3C) Extensible Markup Language (XML) 1.0 Recommendation for document type definitions (DTDs), the MSXML Schema specification for XML-Data Reduced (XDR) schemas, and the W3C XML Schema Recommendation for XML Schema definition language (XSD) schemas.

Schemas Property

The Schemas property of XmlValidatingReader provides the reader with access to schemas loaded into the built XmlSchemaCollection. Because these schemas are cached, the reader can validate a schema without having to reload it each time. The use of schemas cached in memory significantly improves performance.

XmlResolver Property

The XmlResolver property of XmlValidatingReader is used to resolve external entities (for example, DTD and schema locations). If you have a custom XmlResolver or if you are accessing a network resource that requires credentials, use this property to specify which XmlResolver to use. To resolve external references in which an XmlResolver is not specified, the reader uses a default XmlUrlResolver. The XmlUrlResolver class resolves file and HTTP protocols.

The XmlResolver is also used to process xs:include and xs:import elements in XML Schemas. If xs:include or xs:import elements have a relative path, the XmlValidatingReader resolves the relative path using the BaseURI property of the XmlValidatingReader. For more information about the XmlResolver, see Resolving Resources Using the XmlResolver.

In This Section