Latest web development tutorials

XMLスキーマの制限要素

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回発生する可能性があることを宣言します。)

属性 描述
id 可选。规定该元素的唯一的 ID。
base 必需。规定在该 schema(或由指定的命名空间指示的其他 schema)中定义的内建数据类型、simpleType 或 complexType 元素的名称。
any attributes 可选。规定带有 non-schema 命名空间的任何其他属性。

例1

次の例は、制約を持つ要素を定義し、の「年齢」と命名されています。 年齢の値が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

この例では、名前の "イニシャル"要素を定義します。 「イニシャル」要素は、制限付きのシンプルなタイプです。 許容値は、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

この例では、名前の「パスワード」要素を定義します。 「パスワード」要素は、制限付きのシンプルなタイプです。 値は、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

この例では、制約を使用して定義された複合型を示しています。 その固定された要素の値、由来常連複合型から複合型」Chinese_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スキーマリファレンス 完全なXMLスキーマリファレンス