Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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)

static member Validate : 
        source:XDocument * 
        schemas:XmlSchemaSet * 
        validationEventHandler:ValidationEventHandler -> unit

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 a null reference (Nothing in Visual Basic), throws an exception upon validation errors.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type XDocument. 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).

ExceptionCondition
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

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft