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 Class

This class contains the LINQ to XML extension methods for XSD validation.

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

'Declaration
<ExtensionAttribute> _
Public NotInheritable Class Extensions
'Usage
You do not need to declare an instance of a static class in order to access its members.

This class also contains methods to get the post-schema-validation infoset (PSVI) of a validated XML node.

When you validate an XDocument, XElement, or XAttribute, you can also optionally populate the XML tree with the post-schema-validation infoset. PSVI information is added as an annotation of type System.Xml.Schema.XmlSchemaInfo.

The XSD in Sample XSD File: Customers and Orders contains a schema that can be used to validate the XML document in Sample XML File: Customers and Orders (LINQ to XML). The following example loads the schema and the document, validates the document, changes the document so that the xs:key and xs:keyref relationship is not valid, and then attempts to validate again.

Dim errors As Boolean = False

Private Sub XSDErrors(ByVal o As Object, ByVal e As ValidationEventArgs)
    Console.WriteLine("{0}", e.Message)
    errors = True
End Sub

Sub Main()
    Dim schemas As XmlSchemaSet = New XmlSchemaSet()
    schemas.Add("", "CustomersOrders.xsd")

    Console.WriteLine("Validating custOrd")
    Dim custOrd As XDocument = XDocument.Load("CustomersOrders.xml")
    errors = False
    custOrd.Validate(schemas, AddressOf XSDErrors)
    Console.WriteLine("custOrd {0}", IIf(errors, "did not validate", "validated"))

    Console.WriteLine()
    Console.WriteLine("Validating custOrd")
    ' Modify the source document so that it will not validate.
    custOrd.Root.Element("Orders").Element("Order").Element("CustomerID").Value = "AAAAA"
    errors = False
    custOrd.Validate(schemas, AddressOf XSDErrors)
    Console.WriteLine("custOrd {0}", IIf(errors, "did not validate", "validated"))
End Sub

This example produces the following output:

Validating custOrd
custOrd validated

Validating custOrd
The key sequence 'AAAAA' in Keyref fails to refer to some key.
custOrd did not validate

System.Object
  System.Xml.Schema.Extensions

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

Community Additions

Show:
© 2017 Microsoft