XML スキーマ restriction 要素
完全なXMLスキーマリファレンス
定義と用法
restriction 要素は、simpleType、simpleContent、または complexContent 定義の制約を定義します。
要素情報
- 親要素: simpleType, simpleContent, complexContent
構文
<restriction
id=ID
base=QName
any attributes
>
simpleType の内容:
(annotation?,(simpleType?,(minExclusive|minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
simpleContent の内容:
(annotation?,(simpleType?,(minExclusive |minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
((attribute|attributeGroup)*,anyAttribute?))
complexContent の内容:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>
(restriction 要素内で、? 記号は要素が 0 または 1 回出現できることを宣言します)
属性 |
説明 |
id |
オプション。 要素へユニークな ID を指定する |
base |
必須。組込みデータ型、simpleType要素、またはこのスキーマや別のスキーマで定義された
complexType 要素の名前を指定する
|
any attributes |
オプション。非スキーマ名前空間を持つ他の属性を指定する
|
例 1
この例は、制約を持つ制限とd "age" という要素を定義しています。age の値は、0 未満
または 100 超にすることはできません:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
例 2
また、この例は、"initials" と言う要素を定義しています。
"initials" 要素は、制約付きの単純型です。唯一の許容値は、a から z までの3つの小文字または大文字です:
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
例 3
この例では、"password" と言う要素を定義しています。
"password" 要素は、制約付きの単純型です。値は、5 ~ 8 文字にする必要があります:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
例 4
この例は、制約を使用した複合型定義を示しています。複合型 "Norwegian_customer" は、
一般的な customer 複合型から派生したもので、country 要素は、"Norway" に固定されています:
<xs:complexType name="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Norwegian_customer">
<xs:complexContent>
<xs:restriction base="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string" fixed="Norway"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
完全なXMLスキーマリファレンス
|