System.Xml.Schema.XmlSchemaSimpleType Class

Assembly: System.Xml.dll
Namespace: System.Xml.Schema
Summary
Class defines a simple type that determines the information and constraints for the values of attributes or elements with text-only content. Represents the World Wide Web Consortium (W3C) simpleType element.
C# Syntax:
public class XmlSchemaSimpleType : XmlSchemaType
Remarks
Simple types are defined by deriving them from existing simple types (built-in data types and derived simple types). A simple type cannot contain elements and cannot have attributes.
Example
The following example shows the use of the XmlSchemaSimpleType class.
using System;
using System.Xml;  
using System.Xml.Schema;

class XMLSchemaExamples {
    public static void Main() {
 
        XmlSchema schema = new XmlSchema();

        // <xs:simpleType name="LotteryNumber">
        XmlSchemaSimpleType LotteryNumberType = new XmlSchemaSimpleType();
        LotteryNumberType.Name = "LotteryNumber";

        // <xs:restriction base="xs:int">
        XmlSchemaSimpleTypeRestriction LotteryNumberRestriction = new XmlSchemaSimpleTypeRestriction();
        LotteryNumberRestriction.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");

        // <xs:minInclusive value="1"/>
        XmlSchemaMinInclusiveFacet minInclusive = new XmlSchemaMinInclusiveFacet();
        minInclusive.Value = "1";
        LotteryNumberRestriction.Facets.Add(minInclusive);

        // <xs:maxInclusive value="99"/>
        XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();
        maxInclusive.Value = "99";
        LotteryNumberRestriction.Facets.Add(maxInclusive);

        LotteryNumberType.Content = LotteryNumberRestriction;
        schema.Items.Add(LotteryNumberType);

        // <xs:simpleType name="LotteryNumberList">
        XmlSchemaSimpleType LotteryNumberListType = new XmlSchemaSimpleType();
        LotteryNumberListType.Name = "LotteryNumberList";

        // <xs:list itemType="LotteryNumber"/>
        XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
        list.ItemTypeName = new XmlQualifiedName("LotteryNumber", "");
        LotteryNumberListType.Content = list;

        schema.Items.Add(LotteryNumberListType);

        // <xs:simpleType name="LotteryNumbers">
        XmlSchemaSimpleType LotteryNumbersType = new XmlSchemaSimpleType();
        LotteryNumbersType.Name = "LotteryNumbers";

        // <xs:restriction base="LotteryNumberList">
        XmlSchemaSimpleTypeRestriction LotteryNumbersRestriction = new XmlSchemaSimpleTypeRestriction();
        LotteryNumbersRestriction.BaseTypeName = new XmlQualifiedName("LotteryNumberList", "");
                
        // <xs:length value="5"/>
        XmlSchemaLengthFacet length = new XmlSchemaLengthFacet();
        length.Value = "5";
        LotteryNumbersRestriction.Facets.Add(length);

        LotteryNumbersType.Content = LotteryNumbersRestriction;

        schema.Items.Add(LotteryNumbersType);

        // <xs:element name="TodaysLottery" type="LotteryNumbers">
        XmlSchemaElement TodaysLottery = new XmlSchemaElement();
        TodaysLottery.Name = "TodaysLottery";
        TodaysLottery.SchemaTypeName = new XmlQualifiedName("LotteryNumbers", "");
        
        schema.Items.Add(TodaysLottery);

        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
 	XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        schema.Write(Console.Out, nsmgr);
    }

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {

        Console.WriteLine(args.Message);
    }
}

    

The following XML file is generated for the preceding code example.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleType name="LotteryNumber">
        <xs:restriction base="xs:int">
            <xs:minInclusive value="1"/>
            <xs:maxInclusive value="99"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="LotteryNumberList">
        <xs:list itemType="LotteryNumber"/>
    </xs:simpleType>
    
    <xs:simpleType name="LotteryNumbers">
        <xs:restriction base="LotteryNumberList">
            <xs:length value="5"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:element name="TodaysLottery" type="LotteryNumbers">
    </xs:element>
    
</xs:schema>

    
See also:
System.Xml.Schema Namespace

System.Xml.Schema.XmlSchemaSimpleType Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Public Properties
Annotation
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation


Gets or sets the annotation property.
BaseSchemaType
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.BaseSchemaType


Gets the object of the simpleType element or complexType element. This is a post-schema-validation-infoset variable.
Content Read-write

Gets or sets one of XmlSchemaSimpleTypeUnion, XmlSchemaSimpleTypeList, or XmlSchemaSimpleTypeRestriction.
Datatype
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.Datatype


Gets the data type that holds the post-compilation value.
DerivedBy
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.DerivedBy


When overridden in a derived class, this property gets information that indicates how this element has been derived from a base type. This property holds the post-compilation value.
Final
(inherited from System.Xml.Schema.XmlSchemaType)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaType.Final


Gets or sets the final property to indicate that no further derivations are allowed.
FinalResolved
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.FinalResolved


Gets the post-compilation value of the Final property that holds the post-compilation value of the Final property.
Id
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id


Gets or sets the string id.
IsMixed
(inherited from System.Xml.Schema.XmlSchemaType)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaType.IsMixed


Indicates that this type has a mixed content model. This property is only valid in a complex type.
LineNumber
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber


Gets or sets the line number in the file to which the schema element refers.
LinePosition
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition


Gets or sets the line position in the file to which the schema element refers.
Name
(inherited from System.Xml.Schema.XmlSchemaType)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaType.Name


Gets or sets the name of the type.
Namespaces
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces


QualifiedName
(inherited from System.Xml.Schema.XmlSchemaType)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaType.QualifiedName


Gets the qualified name for the type built from the Name attribute of this type. This holds the post-compilation value.
SourceUri
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri


Gets or sets the source location for the file that loaded the schema.
UnhandledAttributes
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes


Gets or sets the qualified attributes that do not belong to the schema target namespace.
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 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.XmlSchemaSimpleType Member Details

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

Return to top


Property: Annotation (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation

Summary
Gets or sets the annotation property.
C# Syntax:
public XmlSchemaAnnotation Annotation {get; set;}

Return to top


Property: BaseSchemaType (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.BaseSchemaType

Summary
Gets the object of the simpleType element or complexType element. This is a post-schema-validation-infoset variable.
C# Syntax:
public object BaseSchemaType {get;}
Remarks
The base value must be a QName.

Return to top


Property: Content (read-write)
Summary
Gets or sets one of XmlSchemaSimpleTypeUnion, XmlSchemaSimpleTypeList, or XmlSchemaSimpleTypeRestriction.
C# Syntax:
public XmlSchemaSimpleTypeContent Content {get; set;}
Remarks
The following table shows the ways in which simple types can be defined.

Simple type Description
Restriction Restricts the range of values for the simple type to a subset of those for the inherited simple type.
List Defines a simple type that contains a white space-separated list of values of an inherited simple type.
Union Defines a simple type that contains a union of the values of two or more inherited simple types.

Return to top


Property: Datatype (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.Datatype

Summary
Gets the data type that holds the post-compilation value.
C# Syntax:
public XmlSchemaDatatype Datatype {get;}

Return to top


Property: DerivedBy (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.DerivedBy

Summary
When overridden in a derived class, this property gets information that indicates how this element has been derived from a base type. This property holds the post-compilation value.
C# Syntax:
public XmlSchemaDerivationMethod DerivedBy {get;}
Remarks
The value can contain a list that is a subset of Extension, Restriction, Substitution, List, or Union. The following table shows the values that this property can contain.

Enum Description
None No derivation method specified.
Substitution Derived by Substitution.
Extension Derived by Extension.
Restriction Derived by Restriction.
List Derived by List.
Union Derived by Union.

Return to top


Property: Final (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.Final

Summary
Gets or sets the final property to indicate that no further derivations are allowed.
C# Syntax:
public XmlSchemaDerivationMethod Final {get; set;}
Remarks
The following table shows the values that this property can contain for simple type.

Enum Description
Empty Overrides the schema blockDefault setting allowing any derivations, by restriction, extension, or substitution to take place.
None No derivation method is specified. This is the default. Derivation rules are taken from the schema blockDefault setting.
Substitution Cannot be replaced by a type derived by Substitution.
Extension Cannot be replaced by a type derived by Extension.
Restriction Cannot be replaced by a type derived by Restriction.
All #all . Cannot be replaced by a type derived by any derivation method.

The following table shows the values that this property can contain for complex type.



Enum Description
Empty Overrides the schema blockDefault setting allowing any derivations, by restriction, extension, or substitution to take place.
None No derivation method is specified. This is the default. Derivation rules are taken from the schema blockDefault setting.
Substitution Cannot be replaced by a type derived by Substitution.
Extension Cannot be replaced by a type derived by Extension.
Restriction Cannot be replaced by a type derived by Restriction.
All #all . Cannot be replaced by a type derived by any derivation method.

Return to top


Property: FinalResolved (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.FinalResolved

Summary
Gets the post-compilation value of the Final property that holds the post-compilation value of the Final property.
C# Syntax:
public XmlSchemaDerivationMethod FinalResolved {get;}
Remarks
This value indicates how the type is restricted when the type is extended through restriction. If the type is marked as final, this type cannot be extended.

Return to top


Property: Id (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id

Summary
Gets or sets the string id.
C# Syntax:
public string Id {get; set;}
Remarks
The id value must be of type ID and be unique within the document containing this element.

Optional.

Return to top


Property: IsMixed (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.IsMixed

Summary
Indicates that this type has a mixed content model. This property is only valid in a complex type.
C# Syntax:
public virtual bool IsMixed {get; set;}
Remarks
Thedefault is false. This virtual method is overridden in derived classes.

Return to top


Property: LineNumber (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber

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)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition

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: Name (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.Name

Summary
Gets or sets the name of the type.
C# Syntax:
public string Name {get; set;}
Remarks
The name must be an NCName (no-colon name) as defined in the World Wide Web Consortium (W3C) XML Namespaces specification. Optional. If specified, the name must be unique among all simpleType and complexType elements.

Return to top


Property: Namespaces (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces

C# Syntax:
public XmlSerializerNamespaces Namespaces {get; set;}

Return to top


Property: QualifiedName (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaType.QualifiedName

Summary
Gets the qualified name for the type built from the Name attribute of this type. This holds the post-compilation value.
C# Syntax:
public XmlQualifiedName QualifiedName {get;}

Return to top


Property: SourceUri (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri

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


Property: UnhandledAttributes (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes

Summary
Gets or sets the qualified attributes that do not belong to the schema target namespace.
C# Syntax:
public XmlAttribute[] UnhandledAttributes {get; set;}

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:
~XmlSchemaSimpleType();

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.