最新のWeb開発のチュートリアル
 

XMLスキーマ制限要素


<完全なXMLスキーマリファレンス

定義と使用法

制限要素は、simpleTypeの、simpleContentを、またはcomplexContentを定義の制限を定義します。

要素情報

  • Parent elements: 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

必須。 組み込みデータ型、simpleType要素、またはcomplexType要素の名前は、このスキーマまたは別のスキーマで定義された指定

any attributes 任意。 非スキーマの名前空間を持つ任意の他の属性を指定します。

例1

この例では、という要素を定義し"age"制限を。 年齢の値が100よりも0以上よりも低くすることができません。

<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までの大文字または小文字の文字のTHREEです。

<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"一般顧客複合型から派生し、その国の要素がに固定されている"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スキーマリファレンス