XSD 复合空要素

空の複合要素は内容を含むことができず、属性のみを含むことができます。

複合空要素:

空のXML要素:

<product prodid="1345" />

上の「product」要素には内容が全くありません。無内容の型を定義するために、要素を含む内容のみを含む型を宣言する必要がありますが、実際には要素を宣言しません。例えば、以下のようになります:

<xs:element name="product">
  <xs:complexType>
    <xs:complexContent>
      <xs:restriction base="xs:integer">
        <xs:attribute name="prodid" type="xs:positiveInteger"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

上の例では、複合内容を持つ複合型を定義しました。complexContent要素が示すのは、ある複合型の内容モデルを限定したり拡張したりするつもりであること、そしてinteger限定が属性を宣言しているが要素内容を導入しないことを示しています。

ただし、この「product」要素をさらにコンパクトに宣言することもできます:

<xs:element name="product">
  <xs:complexType>
    <xs:attribute name="prodid" type="xs:positiveInteger"/>
  </xs:complexType>
</xs:element>

または、complexType 要素に名前を付け、"product" 要素にtype属性を設定し、このcomplexType名を参照することで(この方法を使用すると、同じ複合タイプを複数の要素で参照することができます):

<xs:element name="product" type="prodtype"/>
<xs:complexType name="prodtype">
  <xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:complexType>