XSD Composite Type with Mixed Content
- Previous Page XSD Only Text
- Next Page XSD Indicators
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 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:To allow character data to appear between the subelements of "letter", the mixed attribute must be set to "true". The <xs:sequence> element (name, orderid, and shipdate) means that the defined elements must appear in sequence within the "letter" element.
We can also name a complexType element and let the "letter" element's type attribute refer to this name of the 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>
- Previous Page XSD Only Text
- Next Page XSD Indicators