Extensions.Validate Method (XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler)
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
static member Validate : source:XAttribute * partialValidationType:XmlSchemaObject * schemas:XmlSchemaSet * validationEventHandler:ValidationEventHandler -> unit
- Type: System.Xml.Schema.XmlSchemaObject
An XmlSchemaObject that specifies the sub-tree to validate.
Usage NoteIn Visual Basic and C#, you can call this method as an instance method on any object of type XAttribute. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Thrown for XML Schema Definition Language (XSD) validation errors.
You can use this method to validate that an XAttribute conforms to a schema. You typically use this method when you have modified an attribute, 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 just the attribute.
If you pass a null reference (Nothing in Visual Basic) for validationEventHandler, this method raises an exception upon validation errors. Validation warnings will not raise an exception.
To validate an attribute, 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 attribute.
This example produces the following output:
Validating doc1 ... doc1 validated Validating Lang attribute ... lang validated Validating Lang attribute ... The 'Lang' attribute is invalid - The value 'VC' is invalid according to its datatype 'Token' - The Enumeration constraint failed. lang did not validate
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.