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>