XML Schema Tuto...login
XML Schema Tutorial
author:php.cn  update time:2022-04-20 14:13:02

XML Schema composite empty element


XSD Empty element


An empty composite element cannot contain content, but can only contain attributes.


Composite empty element:

An empty XML element:

<product prodid="1345" />

The "product" element above has no content at all. In order to define a contentless type, we must declare a type that can only contain elements in its content, but we will not actually 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 define a composite type with composite content. The complexContent element signals that we intend to qualify or extend the content model of a composite type, while the integer qualification declares an attribute but does not introduce any element 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 give a complexType element a name and then set a type attribute for the "product" element and reference this complexType name (using this method, several elements can all 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>
##