XML Schema Complex Empty Elements
--
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
XML Schema Tutorial
XML Schema Tutorial
XML Schemas Introduction
Why Use XML Schema?
How to Use XML Schema
XML Schema Elements
XSD Simple Elements
XML Schema Attributes
XML Schema Facets
XML Schema Complex Elements
XML Schema Complex Empty Elements
XML Schema Complex Types - Only Contain Elements
XML Schema Complex Elements - Only Contain Text
XML Schema Complex Types - Mixed Content
XML Schema Indicators
XML Schema any Element
XML Schema anyAttribute Element
XML Schema Element Substitution
XML Schema Example
XML Schema String Data Types
XML Schema Date/Time Data Types
XML Schema Numeric Data Types
XML Schema Miscellaneous Data Types
XML Editor
XML Schema Summary
XML Schema Reference Manual
XML Schema Complex Elements
XML Schema Complex Types - Only Contain Elements
XSD Empty Elements
Empty complex elements cannot contain content, they can only contain attributes.
Complex Empty Element:
An empty XML element:
<product prodid="1345" />
Above, the "product" element has no content at all. To define a type with no content, we must declare a type that can only contain elements in its content, but actually we do not declare any elements, like 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 complex type with complex content. The complexContent element signals that we intend to restrict or extend some complex type's content model, and the integer restriction declares an attribute but does not introduce any element content.
However, the "product" element can be declared more compactly like this:
<xs:element name="product">
<xs:complexType>
<xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
Or you can give a name to a complexType element, then set a type attribute for the "product" element and reference 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>
YouTip