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.

XmlSchemaObject Class

Creates an empty schema.

For a list of all members of this type, see XmlSchemaObject Members.

System.Object
   System.Xml.Schema.XmlSchemaObject
      Derived classes

[Visual Basic]
MustInherit Public Class XmlSchemaObject
[C#]
public abstract class XmlSchemaObject
[C++]
public __gc __abstract class XmlSchemaObject
[JScript]
public abstract class XmlSchemaObject

Thread Safety

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

Example

[Visual Basic, C#, C++] The following example displays each schema object.

[Visual Basic] 
Option Strict
Option Explicit

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))
            
            schema.Compile(AddressOf ShowCompileError)
            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
    
    
    Overloads Private Shared Sub DisplayObjects(o As Object)
        DisplayObjects(o, "")
    End Sub 'DisplayObjects
    
    Overloads Private Shared Sub DisplayObjects(o As Object, 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 'DisplayObjects
    
    Private Shared Sub ShowCompileError(sender As Object, e As ValidationEventArgs)
        Console.WriteLine("Validation Error: {0}", e.Message)
    End Sub 'ShowCompileError
End Class 'ValidXSD

[C#] 
using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Reflection;

public class ValidXSD {
    public static int Main() {
        
        string xsd = "example.xsd";

        FileStream fs;
        XmlSchema schema;
        try {
            fs = new FileStream(xsd, FileMode.Open);
            schema = XmlSchema.Read(fs, new ValidationEventHandler(ShowCompileError));

            schema.Compile(new ValidationEventHandler(ShowCompileError));
            if (schema.IsCompiled) {
                DisplayObjects(schema);
            }
            return 0;
        } catch (XmlSchemaException e) {
            Console.WriteLine("LineNumber = {0}", e.LineNumber);
            Console.WriteLine("LinePosition = {0}", e.LinePosition);
            Console.WriteLine("Message = {0}", e.Message);
            Console.WriteLine("Source = {0}", e.Source);
            return -1;
        }
    }
    
    private static void DisplayObjects(object o) {
        DisplayObjects(o, "");
    }
    private static void DisplayObjects(object o, string indent) {
        Console.WriteLine("{0}{1}", indent, o);

        foreach (PropertyInfo property in o.GetType().GetProperties()) {
            if (property.PropertyType.FullName == "System.Xml.Schema.XmlSchemaObjectCollection") {
            
                XmlSchemaObjectCollection childObjectCollection = (XmlSchemaObjectCollection) property.GetValue(o, null);
                
                foreach (XmlSchemaObject schemaObject in childObjectCollection) {
                    DisplayObjects(schemaObject, indent + "\t");
                }
            }
        }
    }
    private static void ShowCompileError(object sender, ValidationEventArgs e) {
        Console.WriteLine("Validation Error: {0}", e.Message);
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::IO;
using namespace System::Reflection;

public __gc class ValidXSD {
public:
    static int main() {
        
        String* xsd = S"example.xsd";

        FileStream* fs;
        XmlSchema* schema;
        try {
            fs = new FileStream(xsd, FileMode::Open);
            schema = XmlSchema::Read(fs, new ValidationEventHandler(0, ShowCompileError));

            schema->Compile(new ValidationEventHandler(0, ShowCompileError));
            if (schema->IsCompiled) {
                DisplayObjects(schema);
            }
            return 0;
        } catch (XmlSchemaException* e) {
            Console::WriteLine(S"LineNumber = {0}", __box(e->LineNumber));
            Console::WriteLine(S"LinePosition = {0}", __box(e->LinePosition));
            Console::WriteLine(S"Message = {0}",e->Message);
            Console::WriteLine(S"Source = {0}",e->Source);
            return -1;
        }
    }
    
private:
    static void DisplayObjects(Object* o) {
        DisplayObjects(o, S"");
    }

    static void DisplayObjects(Object* o, String* indent) {
        Console::WriteLine(S"{0}{1}",indent,o);

        System::Collections::IEnumerator* myEnum = o->GetType()->GetProperties()->GetEnumerator();
        while (myEnum->MoveNext())
        {
            PropertyInfo* property = __try_cast<PropertyInfo*>(myEnum->Current);
            if (property->PropertyType->FullName->Equals(S"System.Xml.Schema.XmlSchemaObjectCollection")) {
            
                XmlSchemaObjectCollection* childObjectCollection = dynamic_cast<XmlSchemaObjectCollection*> (property->GetValue(o, 0));
                
                System::Collections::IEnumerator* myEnum1 = childObjectCollection->GetEnumerator();
                while (myEnum1->MoveNext())
                {
                    XmlSchemaObject* schemaObject = __try_cast<XmlSchemaObject*>(myEnum1->Current);
                    DisplayObjects(schemaObject, String::Concat( indent, S"\t" ));
                }
            }
        }
    }

    static void ShowCompileError(Object* /*sender*/, ValidationEventArgs* e) {
        Console::WriteLine(S"Validation Error: {0}",e->Message);
    }
};

int main()
{
    ValidXSD::main();
}

[Visual Basic, C#, C++] The example uses the example.xsd file as input.

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:group name="testGroup">
  <xs:choice>
    <xs:any namespace="##any"/>
  </xs:choice>
  </xs:group>
  <xs:element name="myElement" >
  <xs:complexType>
    <xs:choice maxOccurs="unbounded">
      <xs:group ref="testGroup" />
    </xs:choice>
  </xs:complexType>
  </xs:element>
</xs:schema>

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Xml (in System.Xml.dll)

See Also

XmlSchemaObject Members | System.Xml.Schema Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft