XmlSchemaSimpleType Class

Represents the simpleType element for simple content from XML Schema as specified by the World Wide Web Consortium (W3C). This class defines a simple type. Simple types can specify information and constraints for the value of attributes or elements with text-only content.

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

public class XmlSchemaSimpleType : XmlSchemaType
public class XmlSchemaSimpleType extends XmlSchemaType
public class XmlSchemaSimpleType extends XmlSchemaType

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.

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";

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

        LotteryNumberType.Content = LotteryNumberRestriction;

        // <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;


        // <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";

        LotteryNumbersType.Content = LotteryNumbersRestriction;


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


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

        XmlSchema compiledSchema = null;

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

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

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args)


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:simpleType name="LotteryNumberList">
        <xs:list itemType="LotteryNumber"/>
    <xs:simpleType name="LotteryNumbers">
        <xs:restriction base="LotteryNumberList">
            <xs:length value="5"/>
    <xs:element name="TodaysLottery" type="LotteryNumbers">

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0