Skip to main content

XSD Elements Only

An elements-only complex type contains an element that contains only other elements.

Complex Types Containing Elements Only

An XML element, "book", that contains only other elements:

<book>
<title>A Great Book</title>
<author>Tom Nolan</author>
<publisher>Tutorial Reference</publisher>
</book>

You can define the "book" element in a schema, like this:

<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
note

The <xs:sequence> tag means that elements defined ("title", "author", "publisher") must appear in that order inside a "book" element.

Or you can give the complexType element a name, and let the "book" element have a type attribute that refers to the name of the complexType

<xs:element name="book" type="bookinfo"/>

<xs:complexType name="bookinfo">
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="publisher" type="xs:string"/>
</xs:sequence>
</xs:complexType>