This documentation is archived and is not being maintained.

XmlSchemaObject Class

Represents the root class for the Xml schema object model hierarchy and serves as a base class for classes such as the XmlSchema class.

Namespace: System.Xml.Schema
Assembly: System.Xml (in system.xml.dll)

public abstract class XmlSchemaObject
public abstract class XmlSchemaObject
public abstract class XmlSchemaObject
Not applicable.

The following example displays each schema object.

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;
            fs = new FileStream(xsd, FileMode.Open);
            schema = XmlSchema.Read(fs, new ValidationEventHandler(ShowCompileError));

            XmlSchemaSet schemaSet = new XmlSchemaSet();
            schemaSet.ValidationEventHandler += new ValidationEventHandler(ShowCompileError);

            XmlSchema compiledSchema = null;

            foreach (XmlSchema schema1 in schemaSet.Schemas())
                compiledSchema = schema1;

            schema = compiledSchema;

            if (schema.IsCompiled)
            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);

The example uses the example.xsd file as input.

<?xml version="1.0"?>
<xs:schema xmlns:xs="">
  <xs:group name="testGroup">
    <xs:any namespace="##any"/>
  <xs:element name="myElement" >
    <xs:choice maxOccurs="unbounded">
      <xs:group ref="testGroup" />

     Derived Classes

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0