XSD Composite Empty Element
- Previous Page XSD Composite Element
- Next Page XSD Only Elements
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 restrict or extend the content model of a complex type, while the integer restriction declares a property but does not introduce any element content.
However, it can also be declared more compactly for this "product" element:
<xs:element name="product"> <xs:complexType> <xs:attribute name="prodid" type="xs:positiveInteger"/> </xs:complexType> </xs:element>
Or you can name a complexType element and then set a type attribute for the "product" element and reference this complexType name (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>
- Previous Page XSD Composite Element
- Next Page XSD Only Elements