System.Xml.Schema.XmlSchemaObject Class

Assembly: System.Xml.dll
Namespace: System.Xml.Schema
Summary
Creates an empty schema.
C# Syntax:
public abstract class XmlSchemaObject
Example
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;
        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;
        }
        catch (Exception e) {
            Console.WriteLine(e);
            return -1;
        }
    }
    
    public static void DisplayObjects(object o) {
        DisplayObjects(o, "");
    }
    public 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");
                }
            }
        }
    }
    public 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: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>

    
See also:
System.Xml.Schema Namespace

System.Xml.Schema.XmlSchemaObject Member List:

Public Properties
LineNumber Read-write

Gets or sets the line number in the file to which the schema element refers.
LinePosition Read-write

Gets or sets the line position in the file to which the schema element refers.
Namespaces Read-write

SourceUri Read-write

Gets or sets the source location for the file that loaded the schema.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Schema.XmlSchemaObject Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected XmlSchemaObject();

Return to top


Property: LineNumber (read-write)
Summary
Gets or sets the line number in the file to which the schema element refers.
C# Syntax:
public int LineNumber {get; set;}
Remarks
LineNumber is used to store the line number when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: LinePosition (read-write)
Summary
Gets or sets the line position in the file to which the schema element refers.
C# Syntax:
public int LinePosition {get; set;}
Remarks
This is used to store the line position when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: Namespaces (read-write)
C# Syntax:
public XmlSerializerNamespaces Namespaces {get; set;}

Return to top


Property: SourceUri (read-write)
Summary
Gets or sets the source location for the file that loaded the schema.
C# Syntax:
public string SourceUri {get; set;}
Remarks
Provides information for exception handling.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XmlSchemaObject();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.