Share via


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 Microsoft XML Core Services (MSXML) Schema specification for XML-Data Reduced (XDR) schemas, and the W3C XML Schema Recommendation for XML Schema definition language (XSD) schemas.

Note

The XmlValidatingReader class is obsolete in the .NET Framework version 2.0. You can create a validating XmlReader instance using the XmlReaderSettings class and the Create method. For more information, see Validating XML Data with XmlReader.

If you had been using the XmlValidatingReader class to expand entities, this functionality has been added to the XmlTextReader class.

The XmlValidatingReader.Schemas property provides the reader with access to schemas loaded into the built-in 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.

The XmlValidatingReader.XmlResolver property specifies the XmlResolver object used to resolve external entities (for example, document type definition (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 XmlValidatingReader.BaseURI property. For more information about the XmlResolver, see Resolving Resources Using the XmlResolver.

In This Section

See Also

Other Resources

XML Documents and Data