Extensions::Validate Method (XDocument^, XmlSchemaSet^, ValidationEventHandler^)
This method validates that an XDocument conforms to an XSD in an XmlSchemaSet.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
public: [ExtensionAttribute] static void Validate( XDocument^ source, XmlSchemaSet^ schemas, ValidationEventHandler^ validationEventHandler )
Parameters
- source
-
Type:
System.Xml.Linq::XDocument^
The XDocument to validate.
- schemas
-
Type:
System.Xml.Schema::XmlSchemaSet^
An XmlSchemaSet to validate against.
- validationEventHandler
-
Type:
System.Xml.Schema::ValidationEventHandler^
A ValidationEventHandler for an event that occurs when the reader encounters validation errors. If null, throws an exception upon validation errors.
| Exception | Condition |
|---|---|
| XmlSchemaValidationException | Thrown for XML Schema Definition Language (XSD) validation errors. |
This extension method validates that the XDocument conforms to the schema content model in XmlSchemaSet.
The following example creates an XmlSchemaSet, then validates two XDocument objects against the schema set. One of the documents is valid, the other is not.
This example produces the following output:
Validating doc1 doc1 validated Validating doc2 The element 'Root' has invalid child element 'Child3'. List of possible elements expected: 'Child2'. doc2 did not validate
Available since 3.5