YouTip LogoYouTip

Schema Complex Elements

XML Schema Complex Types - Element-Only

-- Not Only Learning Technology, But Also Dreams!

XML Schema Tutorial

XML Schema Complex Empty Elements XML Schema Complex Elements – Text-Only

XSD Element-Only


"Element-only" complex type elements are elements that can only contain other elements.


Complex Type Containing Only Elements

The XML element "person" contains only other elements:

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

You can define the "person" element in the 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>

Notice the <xs:sequence>. It means that the defined elements must appear in the "person" element in the order shown above.

Or you can give the complexType element a name and let the "person" element's type attribute reference that name (using this method, several elements can reference the same complex 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>

← Schema Complex TextSchema Complex Empty β†’