System.Xml.XmlDocument.Validate Method

Validates the System.Xml.XmlNode object specified against the XML Schema Definition Language (XSD) schemas in the XmlDocument.Schemas property.

Syntax

public void Validate (System.Xml.Schema.ValidationEventHandler validationEventHandler, XmlNode nodeToValidate)

Parameters

validationEventHandler
The System.Xml.Schema.ValidationEventHandler object that receives information about schema validation warnings and errors.
nodeToValidate
The System.Xml.XmlNode object created from an System.Xml.XmlDocument to validate.

Remarks

The XmlDocument.Validate(System.Xml.Schema.ValidationEventHandler, XmlNode) method validates the XML data in the System.Xml.XmlNode object against the schemas contained in the XmlDocument.Schemas property. The XmlDocument.Validate(System.Xml.Schema.ValidationEventHandler, XmlNode) method performs infoset augmentation. Specifically, after successful validation, schema defaults are applied, text values are converted to atomic values as necessary, and type information is associated with validated information items. The result is a previously un-typed XML sub-tree in the System.Xml.XmlDocument replaced with a typed sub-tree.

The following are important notes to consider when using the XmlDocument.Validate(System.Xml.Schema.ValidationEventHandler, XmlNode) method.

  • Schema location hints like xsi:schemaLocation or xsi:noNamespaceSchemaLocation are ignored.

  • Inline schemas are ignored.

  • If schema validation errors occur during validation the System.Xml.XmlDocument becomes partially validated with some nodes with correct type information and some without.

If the node to validate is the root node, the validation process includes checking for uniqueness and reference constraints (xs:ID, xs:IDREF, xs:key, xs:keyref, and xs:unique); otherwise, uniqueness and reference constraints are omitted.

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0