Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Extensions::Validate Method (XAttribute^, XmlSchemaObject^, XmlSchemaSet^, ValidationEventHandler^)

 

This method validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet.

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

public:
[ExtensionAttribute]
static void Validate(
	XAttribute^ source,
	XmlSchemaObject^ partialValidationType,
	XmlSchemaSet^ schemas,
	ValidationEventHandler^ validationEventHandler
)

Parameters

source
Type: System.Xml.Linq::XAttribute^

The XAttribute to validate.

partialValidationType
Type: System.Xml.Schema::XmlSchemaObject^

An XmlSchemaObject that specifies the sub-tree 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.

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 null 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:

  1. Validate that a document conforms to a schema.

  2. Add the post-schema-validation infoset (PSVI) by calling the Validate extension method.

  3. Call the GetSchemaInfo extension method to retrieve an object that implements IXmlSchemaInfo. From the retrieved object, you can get an XmlSchemaObject.

After you have an instance of an XmlSchemaObject, you can use this method to validate an attribute.

No code example is currently available or this language may not be supported.

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

.NET Framework
Available since 3.5
Return to top
Show:
© 2017 Microsoft