XML Schemaのextension要素

定義と用法

extension要素はsimpleTypeまたはcomplexTypeの要素に対して拡張を行います。

要素情報

出現回数 一度
親要素 complexContent
内容 annotation、attribute、attributeGroup、anyAttribute、choice、all、sequence、group

文法

<extension
id=ID 
base=QName
any attributes
>
(annotation?,((group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?)))
</extension>
属性 説明
id 任意。この要素のユニークなIDを指定します。
base 必須。内建データタイプ、simpleType、またはcomplexType要素の名前を指定します。
xml:lang 任意。内容に使用する言語を指定します。

(? 符号はextension要素内で宣言され、この要素は0回または1回のみ出現できます。* 符号はこの要素が0回または複数回出現可能です。)

例1

以下の例では、既存のsimpleTypeに対して属性を追加して拡張しています:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="size">
  <xs:restriction base="xs:string">
    <xs:enumeration value="small" />
    <xs:enumeration value="medium" />
    <xs:enumeration value="large" />
  </xs:restriction>
</xs:simpleType>
<xs:complexType name="jeans">
  <xs:simpleContent>
    <xs:extension base="size">
      <xs:attribute name="sex">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="male" />
            <xs:enumeration value="female" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>
</xs:schema>

例2

以下の例では、既存のcomplexType要素に対して3つの要素を追加して拡張しています:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo">
  <xs:complexContent>
    <xs:extension base="personinfo">
      <xs:sequence>
        <xs:element name="address" type="xs:string"/>
        <xs:element name="city" type="xs:string"/>
        <xs:element name="country" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>
</xs:schema>