単純型を定義します。単純型は、属性値またはテキストだけのコンテンツを持つ要素に対する制約や情報を決定します。
<simpleType
final = (#all | (list | union | restriction))
id = ID
name = NCName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (restriction | list | union))
</simpleType>
属性
final
派生の種類。final 属性は、この simpleType 要素についての、指定した種類の派生を抑止します。値として、#all か、または list、union、restriction のいずれかのサブセットであるリストを設定できます。list
リストによる派生を抑止します。
union
共用体による派生を抑止します。
restriction
制限による派生を抑止します。
#all
すべての派生 (リスト、共用体、制限) を抑止します。
省略可能です。
id
この要素の ID。id の値は ID 型である必要があり、この要素を含んでいるドキュメント内で一意である必要があります。省略可能です。
name
型の名前。この名前は、『XML Namespaces』の仕様に定義されているとおり、コロンを含まない名前 (NCName) である必要があります。name を指定する場合、名前はすべての simpleType 要素および complexType 要素を通じて一意である必要があります。
name は、simpleType 要素が schema 要素の子である場合は必須であり、それ以外の場合は指定できません。
要素情報
出現回数 |
無制限 |
親要素 |
attribute、element、list、restriction (simpleType)、schema、union |
コンテンツ |
解説
単純型は、既存の単純型 (組み込みデータ型および派生した単純型) から派生させて定義します。単純型には要素や属性を含めることはできません。
単純型は次のいずれかの方法で定義できます。
restriction |
単純型の値の範囲を、継承した単純型の値の範囲のサブセットに制限します。 |
list |
空白で区切られた、継承した単純型の値リストを含む単純型を定義します。 |
union |
複数の継承した単純型の値の共用体を含む単純型を定義します。 |
complexType 要素内または attribute 要素内に含まれる simpleType 宣言は、その単純型が、その単純型を含む complexType または attribute のスコープを持つことを定義します。simpleType 宣言が schema 要素を親とする場合、その simpleType は、そのスキーマ内のグローバル スコープを持ちます。
定義した単純型は、属性宣言、要素宣言、または (別の要素宣言内で使用できる) complexType 定義内で使用できます。
例
restriction 要素、list 要素、および union 要素を使用した単純型定義の例を次に示します。
restriction
整数値を最小値 0 から最大値 100 の範囲内に制限する単純型 (freezeboilrangeinteger) を次に示します。
<xs:simpleType name="freezeboilrangeInteger">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
list
日付の一覧をコンテンツとして指定できる単純型 (listOfDates) を次に示します (それぞれのリスト項目の日付を空白で区切る必要があります)。
<xs:simpleType name="listOfDates">
<xs:list itemType="xs:date"/>
</xs:simpleType>
union
2 つの列挙値の集合を定義する 2 つの別々の単純型の和集合として存在する単純型 (allframesize) を次に示します。一方の単純型はロード バイクのサイズを整数値の集合として定義し、もう一方の単純型はマウンテン バイクのサイズを表す文字列 ('large'、'medium'、'small' など) を列挙します。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="allframesize">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="roadbikesize"/>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="mountainbikesize"/>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>
<xs:simpleType name="roadbikesize">
<xs:restriction base="xs:positiveInteger">
<xs:enumeration value="46"/>
<xs:enumeration value="52"/>
<xs:enumeration value="55"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="mountainbikesize">
<xs:restriction base="xs:string">
<xs:enumeration value="small"/>
<xs:enumeration value="medium"/>
<xs:enumeration value="large"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
その他のリソース
詳細については、www.w3.org/TR/2001/REC-xmlschema-1-20010502/#element-all で公開されている、W3C 勧告『XML Schema Part 1: Structures』を参照してください。