XmlReaderSettings.ValidationType Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a value indicating whether the XmlReader will perform validation or type assignment when reading.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public ValidationType ValidationType { get; set; }

Property Value

Type: System.Xml.ValidationType

One of the ValidationType values that indicates whether XmlReader will perform validation or type assignment when reading. The default is ValidationType.None.

The following table describes the ValidationType values.


The Auto and XDR enumeration values are obsolete in .NET Framework version 2.0.




Validation is performed using a document type definition (DTD).


The DtdProcessing property must also be set to Parse.


The XmlReader does not validate data, or perform any type assignment.


Validation and type assignment is performed using an XML Schema definition language (XSD) schema. The reader accesses the XML Schema using the following:

  • Uses the Schemas property to access the XmlSchemaSet object associated with this reader.

  • Uses the in-line schema contained in the XML instance document. (The ProcessInlineSchema option must be enabled.)

  • Uses the XML Schema specified by schema location hints (xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute) found in the XML instance document. (The ProcessSchemaLocation option must be enabled.)

The following example validates using a schema stored in the XmlSchemaSet.

using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;

public class Sample {

  public static void Main() {

    // Create the XmlSchemaSet class.
    XmlSchemaSet sc = new XmlSchemaSet();

    // Add the schema to the collection.
    sc.Add("urn:bookstore-schema", "books.xsd");

    // Set the validation settings.
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ValidationType = ValidationType.Schema;
    settings.Schemas = sc;
    settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);

    // Create the XmlReader object.
    XmlReader reader = XmlReader.Create("booksSchemaFail.xml", settings);

    // Parse the file. 
    while (reader.Read());


  // Display any validation errors.
  private static void ValidationCallBack(object sender, ValidationEventArgs e) {
    Console.WriteLine("Validation Error: {0}", e.Message);

The sample uses the following input files:


<?xml version='1.0'?>
<bookstore xmlns="urn:bookstore-schema">
  <book genre="novel">
    <title>The Confidence Man</title>
  <book genre="philosophy">
    <title>The Gorgias</title>


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

 <xsd:element name="bookstore" type="bookstoreType"/>

 <xsd:complexType name="bookstoreType">
  <xsd:sequence maxOccurs="unbounded">
   <xsd:element name="book"  type="bookType"/>

 <xsd:complexType name="bookType">
   <xsd:element name="title" type="xsd:string"/>
   <xsd:element name="author" type="authorName"/>
   <xsd:element name="price"  type="xsd:decimal"/>
  <xsd:attribute name="genre" type="xsd:string"/>

 <xsd:complexType name="authorName">
   <xsd:element name="first-name"  type="xsd:string"/>
   <xsd:element name="last-name" type="xsd:string"/>


.NET Framework
Available since 2.0
Return to top