Partilhar via


Validation Types of the XmlValidatingReader

The ValidationType property determines the type of validation performed by the XmlValidatingReader. You must set this property before calling the Read method. If external document type definitions (DTDs) or schemas are required for validation, the XmlResolver property is used.

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.

ValidationType Enumeration

The ValidationType property can be set to one of the ValidationType enumeration values. The following sections describe the ValidationType values.

ValidationType.Auto

This is the default value for the ValidationType property. The following table shows the rules for validation when the ValidationType property is set to Auto.

DTD or schema

ValidationType.Auto

No DTD or schema

Parses the XML without validation. No exception is thrown. No type information is supplied.

DTD

Performs DTD validation. Default attributes and entities are expanded. General entities are loaded and parsed only if they are used (expanded). No type information is supplied.

XML Schema (reference or inline)

Performs XML Schema definition language (XSD) validation. Validates with the schema. Default attributes are expanded. Type information is supplied.

XDR schema (reference or inline)

Performs XML-Data Reduced (XDR) schema validation. Validates with the schema. Default attributes are expanded. Type information is supplied.

DTD and XML Schema or XDR schema (reference or inline)

Performs DTD/XML Schema/XDR validation according to the first occurrence of the validation type. DTD validation always takes precedence over other validation types.

ValidationType.DTD

If the ValidationType.DTD value is specified, the XmlValidatingReader validates the document according to the DTD. The following table shows the rules for validation when the ValidationType property is set to ValidationType.DTD.

DTD or schema

ValidationType.DTD

No DTD or schema

Returns a No DTD found warning at the root element. No exception is thrown. No type information is supplied.

DTD

Performs DTD validation. Default attributes and entities are expanded. General entities are loaded and parsed only if they are used (expanded). No type information is supplied.

XML Schema (reference or inline)

Returns a No DTD found warning at the root element. An XmlException is thrown for mixed validation types when schema is found.

XDR schema (reference or inline)

Returns a No DTD found warning at the root element. An XmlException is thrown for mixed validation types when schema is found.

DTD and XML Schema or XDR schema (reference or inline)

Performs DTD validation. Default attributes and entities are expanded.

ValidationType.Schema

If the ValidationType.Schema value is set, the XmlValidatingReader validates the document according to the XML Schemas, including inline schemas. The following table shows the rules for validation when the ValidationType property is set to ValidationType.Schema.

DTD or schema

ValidationType.Schema

No DTD or schema

Returns a No schema found warning for each element.

DTD

An XmlException is thrown for mixed validation types.

XML Schema (reference or inline)

Performs XML Schema validation. Validates with a schema. Default attributes are expanded from schema. Type information is supplied.

XDR schema (reference or inline)

An XmlException is thrown for mixed validation types.

DTD and XML Schema or XDR schema (reference or inline)

Performs XML Schema validation. Default attributes are expanded from schema. Type information is supplied. If a DTD or XDR schema is found, an XmlException is thrown for mixed validation types.

ValidationType.XDR

If the ValidationType.XDR value is set, the XmlValidatingReader validates the document according to XDR schemas, including inline schemas. The following table shows the rules for validation when the ValidationType property is set to ValidationType.XDR.

DTD or schema

ValidationType.XDR

No DTD or schema

Returns a final warning that no validation has occurred.

DTD

An XmlException is thrown for mixed validation types.

XML Schema (reference or inline)

An XmlException is thrown for mixed validation types.

XDR schema (reference or inline)

Performs XDR validation. Validates with a schema. Default attributes are expanded from schema. Type information is supplied.

DTD and XML Schema or XDR schema (reference or inline)

Performs XDR validation. Default attributes are expanded from schema. Type information is supplied. If a DTD or XML Schema is found, an XmlException is thrown for mixed validation types.

ValidationType.None

The ValidationType.None value creates a non-validating parser that complies with the World Wide Web Consortium (W3C) Extensible Markup Language (XML) 1.0 Recommendation. Default attributes are reported, and general entities can be resolved. No validation errors are thrown. The following table shows the rules for validation when the ValidationType property is set to ValidationType.None.

DTD or schema

ValidationType.None

No DTD or schema

Parses the XML without validation. No exception is thrown. No type information is supplied.

DTD

An XML 1.0 compliant non-validating parser is created. No DTD validation is performed. Default attributes and entities are expanded from the DTD. No type information is supplied.

XML Schema (reference or inline)

Parses the XML without validation. No exception is thrown. Default attributes are not expanded from the schema. No type information is supplied.

XDR schema (reference or inline)

Parses the XML without validation. No exception is thrown. Default attributes are not expanded from the schema. No type information is supplied.

DTD and XML Schema or XDR schema (reference or inline)

An XML 1.0 compliant non-validating parser is created. No DTD validation is performed. Default attributes and entities are expanded from the DTD. No type information is supplied.

The XmlValidatingReader throws an InvalidOperationException if the ValidationType property is set after the first Read method.

See Also

Concepts

Reading XML with the XmlReader

Other Resources

Using the XmlReader Class