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

XML Schema Composite Type - Mixed Content


May 28, 2021 XML Schema


Table of contents


XSD hybrid content

This section introduces you to Composite types with mixed content in XML Schema.

Mixed composite types can contain properties, elements, and text.


A composite type with mixed content

XML elements, "letter", contain text and other elements:

<letter>
Dear Mr.<name>John Smith</name>.
Your order <orderid>1032</orderid>
will be shipped on <shipdate>2001-07-13</shipdate>.
</letter>

The following schema declares this "letter" element:

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

Note: In order for character data to appear between the child elements of "letter," the mixed property must be set to "true." The label (name, orderid, and shipdate) means that the defined element must appear inside the "letter" element in turn.

We can also name the complexType element and have the type property of the "letter" element refer to the name of complexType (in this way, several elements can refer to the same composite type):

<xs:element name="letter" type="lettertype"/>

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