XmlSchemaObject Class represents the root class for the Xml schema object model : XML Schema « XML « VB.Net






XmlSchemaObject Class represents the root class for the Xml schema object model

 

Option Strict On
Option Explicit On

Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class ValidXSD

    Public Shared Sub Main()

        Dim xsd As String = "example.xsd"

        Dim fs As FileStream
        Dim schema As XmlSchema
        Try
            fs = New FileStream(xsd, FileMode.Open)
            schema = XmlSchema.Read(fs, New ValidationEventHandler(AddressOf ShowCompileError))

            Dim schemaSet As New XmlSchemaSet()
            AddHandler schemaSet.ValidationEventHandler, AddressOf ShowCompileError

            schemaSet.Add(schema)
            schemaSet.Compile()

            Dim compiledSchema As XmlSchema = Nothing

            For Each schema1 As XmlSchema In schemaSet.Schemas()
                compiledSchema = schema1
            Next

            schema = compiledSchema

            If schema.IsCompiled Then
                DisplayObjects(schema)
            End If

        Catch e As XmlSchemaException
            Console.WriteLine("LineNumber = {0}", e.LineNumber)
            Console.WriteLine("LinePosition = {0}", e.LinePosition)
            Console.WriteLine("Message = {0}", e.Message)
            Console.WriteLine("Source = {0}", e.Source)

        End Try
    End Sub 'Main


    Private Overloads Shared Sub DisplayObjects(ByVal o As Object)
        DisplayObjects(o, "")
    End Sub

    Private Overloads Shared Sub DisplayObjects(ByVal o As Object, ByVal indent As String)
        Console.WriteLine("{0}{1}", indent, o)

        Dim property1 As PropertyInfo
        For Each property1 In o.GetType().GetProperties()
            If property1.PropertyType.FullName = "System.Xml.Schema.XmlSchemaObjectCollection" Then

                Dim childObjectCollection As XmlSchemaObjectCollection = CType(property1.GetValue(o, Nothing), XmlSchemaObjectCollection)

                Dim schemaObject As XmlSchemaObject
                For Each schemaObject In childObjectCollection
                    DisplayObjects(schemaObject, indent + ControlChars.Tab)
                Next schemaObject
            End If
        Next property1
    End Sub

    Private Shared Sub ShowCompileError(ByVal sender As Object, ByVal e As ValidationEventArgs)
        Console.WriteLine("Validation Error: {0}", e.Message)
    End Sub 'ShowCompileError
End Class 'ValidXSD

   
  








Related examples in the same category

1.Compare the XML document generated from DataSet and Original one
2.Read XML without schema and output its structureRead XML without schema and output its structure
3.Output data relation from XML document
4.Generate XML Schema from XML document
5.XMl schema generatorXMl schema generator
6.Validating XML documents against Schemas
7.Validating a Document using the Validate Method
8.XDocument XML schema validation
9.XmlSchema represents an XML Schema
10.Add XmlSchemaElement to XmlSchema
11.Create XmlSchemaComplexType
12.XmlSchemaAll Class represents the World Wide Web Consortium (W3C) all element (compositor).
13.XmlSchemaAny Class represents the World Wide Web Consortium (W3C) any element.
14.XmlSchemaAnyAttribute Class represents the World Wide Web Consortium (W3C) anyAttribute element.
15.XmlSchemaAppInfo Class represents the World Wide Web Consortium (W3C) appinfo element.
16.XmlSchemaAttribute Class represents attribute element from XML Schema
17.XmlSchemaAttributeGroup Class represents attributeGroup element from XML Schema
18.XmlSchemaChoice Class represents choice element from XML Schema
19.XmlSchemaComplexContent represents complexContent element from XML Schema
20.XmlSchemaElement MinOccurs MaxOccursString
21.XmlSchemaComplexType Class represents complexType element from XML Schema
22.XmlSchemaDocumentation Class represents documentation element from XML Schema
23.XmlSchemaEnumerationFacet Class represents enumeration facet from XML Schema
24.XmlSchemaException Class returns detailed information about the schema exception.
25.XmlSchemaFractionDigitsFacet Class sets a restriction for the fraction value of a simpleType element
26.XmlSchemaGroup Class represents group element from XML Schema
27.XmlSchemaInclude Class represents include element from XML Schema
28.XmlSchemaLengthFacet Class represents the length facet from XML Schema
29.XmlSchemaMaxExclusiveFacet Class represents the maxExclusive element from XML Schema
30.XmlSchemaNotation represents the notation element from XML Schema
31.XmlSchemaSimpleContent Class represents simpleContent element from XML Schema
32.XmlSchemaSimpleTypeUnion Class represents the union element for simple types from XML Schema
33.XmlSchemaWhiteSpaceFacet Class tepresents the World Wide Web Consortium (W3C) whiteSpace facet.
34.XmlSchemaAnnotation Class represents the World Wide Web Consortium (W3C) annotation element.
35.XmlSchemaAttribute Class represents the attribute element from the XML Schema
36.XmlSchemaAttributeGroup Class represents the attributeGroup element from the XML Schema
37.XmlSchemaComplexContent Class represents complexContent element from XML Schema
38.Extensions.Validate validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet.
39.Extensions.Validate validates that an XDocument conforms to an XSD in an XmlSchemaSet.
40.Validates that an XDocument conforms to an XSD in an XmlSchemaSet
41.Validates that an XElement sub-tree conforms to a specified XmlSchemaObject and an XmlSchemaSet.
42.XmlSchemaSet contains a cache of XML Schema definition language (XSD) schemas.
43.Create substitutionGroup