XmlDocument.Validate Method (ValidationEventHandler, XmlNode)


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

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

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

public void Validate(
	ValidationEventHandler validationEventHandler,
	XmlNode nodeToValidate


Type: System.Xml.Schema.ValidationEventHandler

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

Type: System.Xml.XmlNode

The XmlNode object created from an XmlDocument to validate.

Exception Condition

The XmlNode object parameter was not created from an XmlDocument.


The XmlNode object parameter is not an element, attribute, document fragment, or the root node.


A schema validation event occurred and no ValidationEventHandler object was specified.

The Validate method validates the XML data in the XmlNode object against the schemas contained in the Schemas property. The Validate 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 XmlDocument replaced with a typed sub-tree.

The following are important notes to consider when using the Validate method.

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

  • Inline schemas are ignored.

  • If schema validation errors occur during validation the 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.

For an example of the Validate method, see the Validate method.

.NET Framework
Available since 2.0
Return to top