XmlSchemaValidator Class
Represents an XML Schema Definition Language (XSD) Schema validation engine. The XmlSchemaValidator class cannot be inherited.
Assembly: System.Xml (in System.Xml.dll)
The XmlSchemaValidator type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | LineInfoProvider | Gets or sets the line number information for the XML node being validated. |
![]() ![]() | SourceUri | Gets or sets the source URI for the XML node being validated. |
![]() ![]() | ValidationEventSender | Gets or sets the object sent as the sender object of a validation event. |
![]() ![]() | XmlResolver | Sets the XmlResolver object used to resolve xs:import and xs:include elements as well as xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes. |
| Name | Description | |
|---|---|---|
![]() ![]() | AddSchema | Adds an XML Schema Definition Language (XSD) schema to the set of schemas used for validation. |
![]() ![]() | EndValidation | Ends validation and checks identity constraints for the entire XML document. |
![]() ![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetExpectedAttributes | Returns the expected attributes for the current element context. |
![]() ![]() | GetExpectedParticles | Returns the expected particles in the current element context. |
![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | GetUnspecifiedDefaultAttributes | Validates identity constraints on the default attributes and populates the ArrayList specified with XmlSchemaAttribute objects for any attributes with default values that have not been previously validated using the ValidateAttribute method in the element context. |
![]() ![]() | Initialize() | Initializes the state of the XmlSchemaValidator object. |
![]() ![]() | Initialize(XmlSchemaObject) | Initializes the state of the XmlSchemaValidator object using the XmlSchemaObject specified for partial validation. |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | SkipToEndElement | Skips validation of the current element content and prepares the XmlSchemaValidator object to validate content in the parent element's context. |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() ![]() | ValidateAttribute(String, String, String, XmlSchemaInfo) | Validates the attribute name, namespace URI, and value in the current element context. |
![]() ![]() | ValidateAttribute(String, String, XmlValueGetter, XmlSchemaInfo) | Validates the attribute name, namespace URI, and value in the current element context. |
![]() ![]() | ValidateElement(String, String, XmlSchemaInfo) | Validates the element in the current context. |
![]() ![]() | ValidateElement(String, String, XmlSchemaInfo, String, String, String, String) | Validates the element in the current context with the xsi:Type, xsi:Nil, xsi:SchemaLocation, and xsi:NoNamespaceSchemaLocation attribute values specified. |
![]() ![]() | ValidateEndElement(XmlSchemaInfo) | Verifies if the text content of the element is valid according to its data type for elements with simple content, and verifies if the content of the current element is complete for elements with complex content. |
![]() ![]() | ValidateEndElement(XmlSchemaInfo, Object) | Verifies if the text content of the element specified is valid according to its data type. |
![]() ![]() | ValidateEndOfAttributes | Verifies whether all the required attributes in the element context are present and prepares the XmlSchemaValidator object to validate the child content of the element. |
![]() ![]() | ValidateText(String) | Validates whether the text string specified is allowed in the current element context, and accumulates the text for validation if the current element has simple content. |
![]() ![]() | ValidateText(XmlValueGetter) | Validates whether the text returned by the XmlValueGetter object specified is allowed in the current element context, and accumulates the text for validation if the current element has simple content. |
![]() ![]() | ValidateWhitespace(String) | Validates whether the white space in the string specified is allowed in the current element context, and accumulates the white space for validation if the current element has simple content. |
![]() ![]() | ValidateWhitespace(XmlValueGetter) | Validates whether the white space returned by the XmlValueGetter object specified is allowed in the current element context, and accumulates the white space for validation if the current element has simple content. |
| Name | Description | |
|---|---|---|
![]() ![]() | ValidationEventHandler | The ValidationEventHandler that receives schema validation warnings and errors encountered during schema validation. |
The XmlSchemaValidator class provides an efficient, high-performance mechanism to validate XML data against XML schemas in a push-based manner. For example, the XmlSchemaValidator class allows you to validate an XML infoset in-place without having to serialize it as an XML document and then reparse the document using a validating XML reader. The XmlSchemaValidator class can also be used to build validation engines over custom XML data sources or as a way to build a validating XML writer.
For more information about the XmlSchemaValidator class, see the XmlSchemaValidator Push-Based Validation topic.
Security Note |
|---|
The ProcessInlineSchema and ProcessSchemaLocation validation flags of an XmlSchemaValidator object are not set be default. Additionally, the XmlResolver property of an XmlSchemaValidator object is nullptr by default. As a result, external schemas referenced in include, imports, or redefine elements are not resolved by default. |
The following example validates the contosoBooks.xml file against the contosoBooks.xsd schema. The example uses the XmlSerializer class to deserialize the contosoBooks.xml file and pass the value of the nodes to the methods of the XmlSchemaValidator class.
The example takes the contosoBooks.xml file as input.
<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
<book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
The example also takes the contosoBooks.xsd as an input.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.contoso.com/books" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="author">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string" />
<xs:element minOccurs="0" name="first-name" type="xs:string" />
<xs:element minOccurs="0" name="last-name" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="price" type="xs:decimal" />
</xs:sequence>
<xs:attribute name="genre" type="xs:string" use="required" />
<xs:attribute name="publicationdate" type="xs:date" use="required" />
<xs:attribute name="ISBN" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
