Udostępnij za pośrednictwem


Validation Options on XmlReaderSettings Class

The XmlReader class can enforce validation using a document type definition (DTD) or XML Schema definition language (XSD) schema. Settings on the XmlReaderSettings object used by the Create method determine what type of data validation, if any, the XmlReader object supports.

Validation Settings

The following table details the validation-specific settings on the XmlReaderSettings class.

Property

Description

ProhibitDtd

Specifies whether to allow DTD processing. The default is to disallow DTD processing.

ValidationType

Specifies whether the XmlReader performs data validation, and what type of validation to perform (DTD or schema). The default is no data validation.

ValidationEventHandler

Specifies an event handler for receiving information about validation events. If an event handler is not provided, an XmlException is thrown on the first validation error.

ValidationFlags

Specifies additional validation settings.

  • AllowXmlAttributes - Allow XML attributes (xml:*) in instance documents even when they are not defined in the schema. The attributes are validated based on their data type.

    This setting is disabled by default.

  • ProcessIdentityConstraints - Process identity constraints (xs:ID, xs:IDREF, xs:key, xs:keyref, xs:unique) encountered during validation.

    This setting is enabled by default.

  • ProcessSchemaLocation - Ignores schemas specified by xsi:schemaLocation or xsi:noNamespaceSchemaLocation attributes.

    This setting is disabled by default.

  • ProcessInlineSchema - Indicates that inline XML Schemas should be processed during validation.

    This setting is disabled by default.

  • ReportValidationWarnings - Indicates that events should be reported if a validation warning occurs. A warning is typically issued when there is no DTD or XML Schema to validate a particular element or attribute against. The ValidationEventHandler is used for notification.

    This setting is disabled by default, and applies to DTD or schema validation.

XmlResolver

Specifies the XmlResolver used to resolve and access any external resources. This can include external entities (for example, DTD and schema locations). The XmlResolver is also used to process any xs:include or xs:import elements contained in the XML Schema. If an XmlResolver is not specified, the XmlReader uses a default XmlUrlResolver with no user credentials.

See Also

Concepts

Reading XML with the XmlReader

Other Resources

Validating XML Data with XmlReader