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)

[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class XmlSchemaObject

The XmlSchemaObject type exposes the following members.

Protected methodSupported by the XNA FrameworkXmlSchemaObjectInitializes a new instance of the XmlSchemaObject class.

Public propertySupported by the XNA FrameworkLineNumberGets or sets the line number in the file to which the schema element refers.
Public propertySupported by the XNA FrameworkLinePositionGets or sets the line position in the file to which the schema element refers.
Public propertySupported by the XNA FrameworkNamespacesGets or sets the XmlSerializerNamespaces to use with this schema object.
Public propertySupported by the XNA FrameworkParentGets or sets the parent of this XmlSchemaObject.
Public propertySupported by the XNA FrameworkSourceUriGets or sets the source location for the file that loaded the schema.

Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)

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="http://www.w3.org/2001/XMLSchema">
  <xs:group name="testGroup">
    <xs:any namespace="##any"/>
  <xs:element name="myElement" >
    <xs:choice maxOccurs="unbounded">
      <xs:group ref="testGroup" />

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft