XMLスキーマ制限要素
❮完全なXMLスキーマリファレンス
定義と使用法
制限要素は、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>
(?記号は、要素が制限要素内で0回または1回発生する可能性があることを宣言します)
Attribute | Description |
---|---|
id | Optional. Specifies a unique ID for the element |
base |
Required. Specifies the name of a built-in data type, simpleType element, or complexType element defined in this schema or another schema |
any attributes | Optional. Specifies any other attributes with non-schema namespace |
例1
この例では、「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
この例では、「イニシャル」と呼ばれる要素も定義しています。「イニシャル」要素は、制限のある単純なタイプです。唯一の許容値は、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」要素は、制限付きの単純なタイプです。値は、最小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」は一般顧客の複合タイプから派生し、その国要素は「ノルウェー」に固定されています。
<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スキーマリファレンス