XmlSchemaSimpleType Class
.NET Framework 2.0
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)
Assembly: System.Xml (in system.xml.dll)
The following example shows the use of the XmlSchemaSimpleType class.
Option Strict On Option Explicit On 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) Dim schemaSet As New XmlSchemaSet() AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne schemaSet.Add(schema) schemaSet.Compile() Dim compiledSchema As XmlSchema = Nothing For Each schema1 As XmlSchema In schemaSet.Schemas() compiledSchema = schema1 Next Dim nsmgr As New XmlNamespaceManager(New NameTable()) nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema") compiledSchema.Write(Console.Out, nsmgr) End Sub 'Main Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs) Console.WriteLine(args.Message) End Sub 'ValidationCallbackOne End Class 'XMLSchemaExamples
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>
System.Object
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaType
System.Xml.Schema.XmlSchemaSimpleType
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaType
System.Xml.Schema.XmlSchemaSimpleType
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.
Community Additions
ADD
Show: