XML Schema restriction要素
完全な XML Schema リファレンスマニュアル
定義と使用法
restriction 要素は、simpleType、simpleContent、または complexContent の定義に対する制約を定義します。
要素情報
- 親要素: simpleType, simpleContent, complexContent
構文
<restriction
id=ID
base=QName
any attributes
>
Content for simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
Content for simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
((attribute|attributeGroup)*,anyAttribute?))
Content for complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>
id=ID
base=QName
any attributes
>
Content for simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
Content for simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
((attribute|attributeGroup)*,anyAttribute?))
Content for complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>
(? 記号は、restriction 要素内でその要素が0回または1回出現できることを宣言します。)
| 属性 | 説明 |
|---|---|
| id | 任意。この要素の一意の ID を規定します。 |
| base | 必須。このスキーマ(または指定した名前空間によって示される他のスキーマ)で定義されている組み込みデータ型、simpleType、または complexType 要素の名前を規定します。 |
| any attributes | 任意。non-schema 名前空間を持つその他の属性を規定します。 |
例 1
次の例では、制約付きで "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>
<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>
<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>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
例 4
この例では、制約を使用した複合型定義を示しています。複合型 "Chinese_customer" は、通常の customer 複合型から派生しており、その country 要素の固定値は "China" です:
<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>
<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 Schema リファレンスマニュアル その他の拡張