XML Schema Tuto...login
XML Schema Tutorial
author:php.cn  update time:2022-04-20 14:13:02

XML Schema composite types – mixed content


XSD Mixed content


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


Composite type with mixed content

The XML element, "letter", contains 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 the "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 to allow character data to appear between the child elements of "letter", The mixed attribute must be set to "true". The <xs:sequence> tags (name, orderid, and shipdate) mean that the defined elements must appear sequentially inside the "letter" element.

We can also give the complexType element a name and let the type attribute 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>

php.cn