Although W3CXML Schema permits mixed content models and describes
them better than in XML DTDS, W3CXML Schema treats them as an add-on
plugged on top of complex content models. The good news is that this
allows control of children elements exactly as we've
just seen for complex contents. The bad news is that we abandon any
control over the child text nodes whose values cannot be constrained
at all, and, of course, the descriptions of the child elements are
subject to the same limitations as in the case of complex content
models. The limitations on unordered content models are probably even
more unfriendly for mixed content models, which are more
"free style," than the limitation
is for complex content models.
7.5.1. Creating Mixed Content Models
This
add-on is implemented
through a mixed attribute in the
xs:complexType(global definition),
which is otherwise used exactly as we've seen for
complex content models. The effect of this attribute when its value
is set to "true" is to allow any text nodes within
the content model, before, between, and after the child elements. The
location, the whitespace processing, and the datatype of these text
nodes cannot be restricted in any way.
Let's go back to the definition of our
title element and change it to accept a reduced
version of XHTML with the a link and an
em element to highlight some parts of its text.
The definition, which was previously done by extending a simple type
to create a simple content complex type, needs to be re-written as a
complex content definition with a mixed attribute set to
"true". The full definition, including the
definition of the a element, the definition of a
markedText complex type and its usage to define
the title element, could be:
<xs:element name="a">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="href" type="xs:anyURI"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:complexType name="markedText" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="em" type="xs:token"/>
<xs:element ref="a"/>
</xs:choice>
<xs:attribute ref="lang"/>
</xs:complexType>
<xs:element name="title" type="markedText"/>
This definition matches elements such as:
<title lang="en">
Being a
<a href="http://dmoz.org/Shopping/Pets/Dogs/">
Dog
</a>
Is a
<em>
Full-Time
</em>
Job
</title>
Note that the length of the title can no longer be restricted.