다음을 통해 공유


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.

The following tables outline the values for the ValidationType property.

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 set, the XmlValidatingReader validates the document according to the DTD. The following table shows the rules for validation when the ValidationType property is set to 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 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 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 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 InvalidOperation exception if the ValidationType property is set after the first Read method.

See Also

Validation of XML with XmlValidatingReader | Validation of XML with Schemas | XmlResolver Class