Extensions.Validate Method (XElement, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler)
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
static member Validate : source:XElement * partialValidationType:XmlSchemaObject * schemas:XmlSchemaSet * validationEventHandler:ValidationEventHandler -> unit
An XmlSchemaObject that specifies the sub-tree to validate.
Thrown for XML Schema Definition Language (XSD) validation errors.
You can use this method to validate that a sub-tree (with an XElement at its root) conforms to a schema. You typically use this method when you have modified a sub-tree, and you want to make sure that it still conforms to its schema. You could validate the entire document, but it takes less processing time to validate a just a sub-tree.
If you pass null for validationEventHandler, then this method raises an exception upon validation errors. Validation warnings will not raise an exception.
To validate a sub-tree, you use an instance of XmlSchemaObject. You can obtain this instance in various ways. An easy way is as follows:
Validate that a document conforms to a schema.
Add the post-schema-validation infoset (PSVI) by calling the Validate extension method.
After you have an instance of an XmlSchemaObject, you can use this method to validate an sub-tree.
This example produces the following output:
Validating doc1 ... doc1 validated Validating Child1 after first edit ... child1 validated Validating Child1 after second edit ... The element 'Child1' has invalid child element 'GrandChild3'. child1 did not validate
Available since 3.5