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

XML Schema Composite Type - Element only


May 28, 2021 XML Schema


Table of contents


XSD contains only elements

This section shows you how to define an element-only XML Schema composite type.

An element of a compound type that contains only elements is an element that can contain only other elements.


The compound type contains only elements

XML elements, "person", contain only other elements:

<person>
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>

You can define the "person" element in schema like this:

<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Keep an eye out for this . I t means that the defined element must appear in the "person" element in the order above.

Alternatively, you can set a name for the complexType element and have the type property of the "person" element refer to the name (for example, with this method, several elements can refer to the same composite type):

<xs:element name="person" type="persontype"/>

<xs:complexType name="persontype">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>

In the next section, you'll learn about XML Schema composite types that contain only text.