Skip to main content

XSD Mixed Elements

A mixed complex type element can contain attributes, elements, and text.

Complex Types with Mixed Elements

Consider this example:

<mail>  
Dear Mr. <name>John Smith</name>.
Your order <orderid>1234</orderid>
will be delivered on <deliverydate>2001-07-13</deliverydate>.
</mail>

We can declare such Complex Text using the following ways:

Use mixed=true

Define complexType with attribute mixed set to true. mixed attribute allow to have character data between elements.

<xs:element name="student">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="deliverydate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
note

Note that the child elements, are surrounded by the <sequence> indicator. This means that the child elements must appear in the same order as they are declared.

You will discover more about indicators in XSD Indicators chapter.

Use ComplexType alone

Define an element of complexType: in this way we can reuse it with more elements.

<xs:element name="student" type="studenttype"/>

<xs:complexType name="studenttype" mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="deliverydate" type="xs:date"/>
</xs:sequence>
</xs:complexType>