Export (0) Print
Expand All

Validating XML Data with XmlReader 

To define the structure of an XML document, as well as its element relationships, data types, and content constraints, you use a document type definition (DTD) or schema. Although an XML document is considered to be well formed if it meets all the syntactical requirements defined by the World Wide Web Consortium (W3C) Extensible Markup Language (XML) 1.0 Recommendation, it is not considered valid unless it is well formed and also conforms to the constraints defined by its DTD or schema. Therefore, although all valid XML documents are well formed, not all well-formed XML documents are valid.

For more information about XML, see the W3C XML 1.0 (Second Edition) Recommendation. For more information about XML Schema, see the W3C XML Schema Part 1: Structures Recommendation and the XML Schema Part 2: Datatypes Recommendation.

The XmlReader class can enforce validation using a DTD or Schema definition language (XSD) schema. The ValidationType property on the XmlReaderSettings class determine whether the XmlReader instance enforces validation.

NoteNote

If you are migrating to the XmlReaderSettings and XmlSchemaSet classes from the XmlValidatingReader class you need to be aware of the following changes in behavior:

The XmlReaderSettings and XmlSchemaSet classes do not support XML-Data Reduced (XDR) schema validation.

There are differences in how elements, with xsi:nil='true' specified, are validated. Elements with white space content are considered valid by the XmlValidatingReader class. Elements with white space content are not considered valid by validating readers created using the XmlReaderSettings class.

In This Section

Validation Options on XmlReaderSettings Class

Describes the specific validation settings.

Validation Using the XmlSchemaSet

Describes how to validate using schemas stored in the XmlSchemaSet.

Validation Using an Inline XML Schema with XmlReader

Describes how to validate using an inline schema.

Validation Using a DTD with XmlReader

Describes how to validate using a DTD.

Validation Using a Wrapped XmlReader Object.

Describes how to validate DOM objects by wrapping an XmlNodeReader object.

Related Sections

Data Conformance Checking with XmlReader

Describes data conformance checks that can be set on the XmlReader class.

Validation of XML with XmlValidatingReader

Describes how to validate using the XmlValidatingReader class.

NoteNote

This should only be used if you require XDR support, or if you need to use the 1.0/1.1 implementation.

Community Additions

ADD
Show:
© 2014 Microsoft