次の方法で共有


XmlSchemaSimpleType クラス

クラスは、テキストだけの内容を持つ属性または要素の値に関する情報や制約を決定する単純型を定義します。W3C (World Wide Web Consortium) simpleType 要素を表します。

この型のすべてのメンバの一覧については、XmlSchemaSimpleType メンバ を参照してください。

System.Object
   System.Xml.Schema.XmlSchemaObject
      System.Xml.Schema.XmlSchemaAnnotated
         System.Xml.Schema.XmlSchemaType
            System.Xml.Schema.XmlSchemaSimpleType

Public Class XmlSchemaSimpleType
   Inherits XmlSchemaType
[C#]
public class XmlSchemaSimpleType : XmlSchemaType
[C++]
public __gc class XmlSchemaSimpleType : public XmlSchemaType
[JScript]
public class XmlSchemaSimpleType extends XmlSchemaType

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

単純型は、既存の単純型 (組み込みデータ型および派生単純型) から派生して定義されます。単純型は、要素を格納できず、属性を持つこともできません。

使用例

[Visual Basic, C#, C++] XmlSchemaSimpleType クラスを使用する例を次に示します。

 
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++] 前述のコード例に対して生成される XML ファイルを次に示します。

<?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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Xml.Schema

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Xml (System.Xml.dll 内)

参照

XmlSchemaSimpleType メンバ | System.Xml.Schema 名前空間