XmlSchemaSimpleType Class
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.
For a list of all members of this type, see XmlSchemaSimpleType Members.
System.Object
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaType
System.Xml.Schema.XmlSchemaSimpleType
[Visual Basic] Public Class XmlSchemaSimpleType Inherits XmlSchemaType [C#] public class XmlSchemaSimpleType : XmlSchemaType [C++] public __gc class XmlSchemaSimpleType : public XmlSchemaType [JScript] public class XmlSchemaSimpleType extends XmlSchemaType
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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
[Visual Basic, C#, C++] The following example shows the use of the XmlSchemaSimpleType class.
[Visual Basic] Option Strict Option Explicit Imports System Imports System.Xml Imports System.Xml.Schema Class XMLSchemaExamples Public Shared Sub Main() Dim schema As New XmlSchema() ' <xs:simpleType name="LotteryNumber"> Dim LotteryNumberType As New XmlSchemaSimpleType() LotteryNumberType.Name = "LotteryNumber" ' <xs:restriction base="xs:int"> Dim LotteryNumberRestriction As New XmlSchemaSimpleTypeRestriction() LotteryNumberRestriction.BaseTypeName = New XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema") ' <xs:minInclusive value="1"/> Dim minInclusive As New XmlSchemaMinInclusiveFacet() minInclusive.Value = "1" LotteryNumberRestriction.Facets.Add(minInclusive) ' <xs:maxInclusive value="99"/> Dim maxInclusive As New XmlSchemaMaxInclusiveFacet() maxInclusive.Value = "99" LotteryNumberRestriction.Facets.Add(maxInclusive) LotteryNumberType.Content = LotteryNumberRestriction schema.Items.Add(LotteryNumberType) ' <xs:simpleType name="LotteryNumberList"> Dim LotteryNumberListType As New XmlSchemaSimpleType() LotteryNumberListType.Name = "LotteryNumberList" ' <xs:list itemType="LotteryNumber"/> Dim list As New XmlSchemaSimpleTypeList() list.ItemTypeName = New XmlQualifiedName("LotteryNumber", "") LotteryNumberListType.Content = list schema.Items.Add(LotteryNumberListType) ' <xs:simpleType name="LotteryNumbers"> Dim LotteryNumbersType As New XmlSchemaSimpleType() LotteryNumbersType.Name = "LotteryNumbers" ' <xs:restriction base="LotteryNumberList"> Dim LotteryNumbersRestriction As New XmlSchemaSimpleTypeRestriction() LotteryNumbersRestriction.BaseTypeName = New XmlQualifiedName("LotteryNumberList", "") ' <xs:length value="5"/> Dim length As New XmlSchemaLengthFacet() length.Value = "5" LotteryNumbersRestriction.Facets.Add(length) LotteryNumbersType.Content = LotteryNumbersRestriction schema.Items.Add(LotteryNumbersType) ' <xs:element name="TodaysLottery" type="LotteryNumbers"> Dim TodaysLottery As New XmlSchemaElement() TodaysLottery.Name = "TodaysLottery" TodaysLottery.SchemaTypeName = New XmlQualifiedName("LotteryNumbers", "") schema.Items.Add(TodaysLottery) schema.Compile(AddressOf ValidationCallbackOne) Dim nsmgr As New XmlNamespaceManager(New NameTable()) nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema") schema.Write(Console.Out, nsmgr) End Sub 'Main Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs) Console.WriteLine(args.Message) End Sub 'ValidationCallbackOne End Class 'XMLSchemaExamples [C#] 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); } } [C++] #using <mscorlib.dll> #using <System.Xml.dll> using namespace System; using namespace System::Xml; using namespace System::Xml::Schema; __gc class XMLSchemaExamples { public: static void main() { XmlSchema* schema = new XmlSchema(); // <xs:simpleType name="LotteryNumber"> XmlSchemaSimpleType* LotteryNumberType = new XmlSchemaSimpleType(); LotteryNumberType->Name = S"LotteryNumber"; // <xs:restriction base="xs:int"> XmlSchemaSimpleTypeRestriction* LotteryNumberRestriction = new XmlSchemaSimpleTypeRestriction(); LotteryNumberRestriction->BaseTypeName = new XmlQualifiedName(S"int", S"http://www.w3.org/2001/XMLSchema"); // <xs:minInclusive value="1"/> XmlSchemaMinInclusiveFacet* minInclusive = new XmlSchemaMinInclusiveFacet(); minInclusive->Value = S"1"; LotteryNumberRestriction->Facets->Add(minInclusive); // <xs:maxInclusive value="99"/> XmlSchemaMaxInclusiveFacet* maxInclusive = new XmlSchemaMaxInclusiveFacet(); maxInclusive->Value = S"99"; LotteryNumberRestriction->Facets->Add(maxInclusive); LotteryNumberType->Content = LotteryNumberRestriction; schema->Items->Add(LotteryNumberType); // <xs:simpleType name="LotteryNumberList"> XmlSchemaSimpleType* LotteryNumberListType = new XmlSchemaSimpleType(); LotteryNumberListType->Name = S"LotteryNumberList"; // <xs:list itemType="LotteryNumber"/> XmlSchemaSimpleTypeList* list = new XmlSchemaSimpleTypeList(); list->ItemTypeName = new XmlQualifiedName(S"LotteryNumber", S""); LotteryNumberListType->Content = list; schema->Items->Add(LotteryNumberListType); // <xs:simpleType name="LotteryNumbers"> XmlSchemaSimpleType* LotteryNumbersType = new XmlSchemaSimpleType(); LotteryNumbersType->Name = S"LotteryNumbers"; // <xs:restriction base="LotteryNumberList"> XmlSchemaSimpleTypeRestriction* LotteryNumbersRestriction = new XmlSchemaSimpleTypeRestriction(); LotteryNumbersRestriction->BaseTypeName = new XmlQualifiedName(S"LotteryNumberList", S""); // <xs:length value="5"/> XmlSchemaLengthFacet* length = new XmlSchemaLengthFacet(); length->Value = S"5"; LotteryNumbersRestriction->Facets->Add(length); LotteryNumbersType->Content = LotteryNumbersRestriction; schema->Items->Add(LotteryNumbersType); // <xs:element name="TodaysLottery" type="LotteryNumbers"> XmlSchemaElement* TodaysLottery = new XmlSchemaElement(); TodaysLottery->Name = S"TodaysLottery"; TodaysLottery->SchemaTypeName = new XmlQualifiedName(S"LotteryNumbers", S""); schema->Items->Add(TodaysLottery); schema->Compile(new ValidationEventHandler(0, ValidationCallbackOne)); XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr->AddNamespace(S"xs", S"http://www.w3.org/2001/XMLSchema"); schema->Write(Console::Out,nsmgr); } static void ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) { Console::WriteLine(args->Message); } }; int main() { XMLSchemaExamples::main(); }
[Visual Basic, C#, C++] 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>
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Xml.Schema
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Xml (in System.Xml.dll)