Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML Schema composite empty elements


May 28, 2021 XML Schema


Table of contents


XSD empty element

About Knowledge of XML Schema composite empty elements, as described in this section.

Empty composite elements cannot contain content, only properties.


Composite empty elements:

An empty XML element:

<product prodid="1345" />

The "product" element above has nothing at all. In order to define a type without content, we must declare a type that can contain only elements in its content, but in fact we do not declare any element, 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 example above, we defined a composite type with composite content. The complexContent element gives the signal that we intend to qualify or expand the content model for a composite type, while the integer qualification declares a property without introducing any elemental content.

However, this "product" element can also be declared more compactly:

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

Or you can name a complexType element, then set a type property for the "product" element and reference the complexType name (by using this method, several elements can refer to the same composite type):

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

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