XSD複合型 - テキストのみ

テキストのみを含む複合要素はテキストと属性を含むことができます。

テキストのみを含む複合要素

このタイプはシンプルな内容(テキストと属性)のみを含んでいますので、この内容にsimpleContent要素を追加する必要があります。シンプルな内容を使用する場合、simpleContent要素内で拡張または限定を定義する必要があります。以下のようになります:

<xs:element name="某个名称">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="basetype">
        ....
        ....
      </xs:extension>     
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

または:

<xs:element name="某个名称">
  <xs:complexType>
    <xs:simpleContent>
      <xs:restriction base="basetype">
        ....
        ....
      </xs:restriction>     
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

ヒント:extensionやrestriction要素を使用して、要素の基本的なシンプル型を拡張または制限してください。

以下は、「shoesize」というXML要素の例で、テキストのみを含んでいます:

<shoesize country="france">35</shoesize>

以下の例では、内容が整数値と定義された複合型が宣言され、「shoesize」要素には「country」属性が含まれています:

<xs:element name="shoesize">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:integer">
        <xs:attribute name="country" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

また、complexType要素に名前を設定し、「shoesize」要素のtype属性にこの名前を参照させてください(この方法を使うと、複数の要素が同じ複合型を参照できます):

<xs:element name="shoesize" type="shoetype"/>
<xs:complexType name="shoetype">
  <xs:simpleContent>
    <xs:extension base="xs:integer">
      <xs:attribute name="country" type="xs:string" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>