XPathNavigator.CheckValidity(XmlSchemaSet, ValidationEventHandler) Method

Definition

Verifies that the XML data in the XPathNavigator conforms to the XML Schema definition language (XSD) schema provided.

public virtual bool CheckValidity (System.Xml.Schema.XmlSchemaSet schemas, System.Xml.Schema.ValidationEventHandler validationEventHandler);

Parameters

schemas
XmlSchemaSet

The XmlSchemaSet containing the schemas used to validate the XML data contained in the XPathNavigator.

validationEventHandler
ValidationEventHandler

The ValidationEventHandler that receives information about schema validation warnings and errors.

Returns

true if no schema validation errors occurred; otherwise, false.

Exceptions

A schema validation error occurred, and no ValidationEventHandler was specified to handle validation errors.

The XPathNavigator is positioned on a node that is not an element, attribute, or the root node or there is not type information to perform validation.

The CheckValidity(XmlSchemaSet, ValidationEventHandler) method was called with an XmlSchemaSet parameter when the XPathNavigator was not positioned on the root node of the XML data.

Remarks

  • The CheckValidity method verifies that the XML data contained in the XPathNavigator conforms to a global type or declaration in the schema or schemas provided in the XmlSchemaSet.

  • The CheckValidity method does not perform infoset augmentation. This means that schema defaults are not applied, text values are not converted to atomic values, and no new type information is associated with information items.

  • Schema xsi:schemaLocation or xsi:noNamespaceSchemaLocation hints in the XML data of are ignored.

  • If the XPathNavigator is positioned on a document node, the validation process includes checking of uniqueness and reference constraints (xs:ID, xs:IDREF, xs:key, xs:keyref, and xs:unique). Otherwise, these checks are omitted.

  • If the XmlSchemaSet passed as a parameter is null and the XPathNavigator is positioned on an element node, the type information exposed by the SchemaInfo property's SchemaType property is used to check the node's validity. If the XmlSchemaSet passed as a parameter is null and the XPathNavigator is positioned on the root node, the SchemaInfo property of the document element (that is, the element child of the root node) is used. In both cases if the SchemaType property of the element's SchemaInfo property is null and the XmlSchemaSet passed as a parameter is null, an InvalidOperationException is thrown because there is no type information to use to perform validation.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1