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 (XDocument^, XmlSchemaSet^, ValidationEventHandler^)

 

This method validates that an XDocument conforms to an XSD in an XmlSchemaSet.

Namespace:   System.Xml.Schema
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.

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

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

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