Skip to main content

XSD Empty Elements

An empty complex element cannot have contents, only attributes.

Complex Empty Elements

A complex empty XML element, called "product":

<product itemid="1234"/>
note

The element above has no content at all!

To define a type with no content, we must define a type that allows elements in its content, but we do not actually declare any elements, like this:

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

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

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

Or you can give the complexType element a name, and let the "product" element have a type attribute that refers to the name of the complexType. In this way, several elements can refer to the same complex type:

<xs:element name="product" type="prodtype"/>

<xs:complexType name="prodtype">
<xs:attribute name="itemid" type="xs:positiveInteger"/>
</xs:complexType>

Table of Contents