XMLスキーマredefine要素

定義と使用方法

redefine要素は、現在のSchema内で外部のスキーマファイルから取得したシンプルおよび複雑なタイプ、グループ、属性グループを再定義することができます。

要素情報

出現回数 無制限
親要素 schema
内容 annotation、attributeGroup、complexType、group、simpleType

文法

<redefine
id=ID
schemaLocation=anyURI
任意の属性
>
(annotation|(simpleType|complexType|group|attributeGroup))*
</redefine>
属性 説明
id オプション。この要素のユニークなIDを指定します。
schemaLocation 必須。schemaドキュメント位置のURI参照。
任意の属性 オプション。non-schema命名空間を持つ他の属性を指定します。

例1

以下の例では、Myschama2.xsdというschemaが示されています。このschemaはMyschama1.xsdで定義された要素を持っています。pnameタイプが再定義されています。このschemaに基づいて、pnameが制約されている要素は「country」要素で終わる必要があります:

Myschema1.xsd:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="pname">
  <xs:sequence>
    <xs:element name="firstname"/>
    <xs:element name="lastname"/>
  </xs:sequence>
</xs:complexType>
<xs:element name="customer" type="pname"/>
</xs:schema>

Myschema2.xsd:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:redefine schemaLocation="Myschema1.xsd">
  <xs:complexType name="pname">
    <xs:complexContent>
      <xs:extension base="pname">
        <xs:sequence>
          <xs:element name="country"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:redefine>
<xs:element name="author" type="pname"/>
</xs:schema>