XSD - Complexe lege elementen

Empty composite elements cannot contain content and can only contain attributes.

Composite empty element:

An empty XML element:

<product prodid="1345" />

The "product" element is completely empty. To define a type without content, we must declare a type that can only contain elements in its content, but in fact we will not declare any elements, such as this:

<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>

In the above example, we defined a complex type with composite content. The signal given by the contentModel element is that we intend to limit or extend the content model of a complex type, while the integer restriction declares an attribute but does not introduce any element content.

However, it is also possible to declare this "product" element more compactly:

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

Of course, you can also name a complexType element and then set a type attribute for the "product" element and refer to this complexType name (by using this method, several elements can refer to the same complex type):

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