W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

Re: Mixed content

From: Eddie Robertsson <erobertsson@allette.com.au>
Date: Mon, 11 Feb 2002 19:50:09 -0500 (EST)
Message-ID: <3C68692F.8682FCBD@allette.com.au>
To: Richard Emslie <rxe@ukshells.co.uk>
CC: xmlschema-dev@w3.org
Hi Richard,

> Hi folks,
>
> Aplogies beforehand for this dumb and simple question... I'm obviously
> misunderstanding something. :-)
>
> In a DTD, one can declare mixed content as follows:
>
> ...
> <!ELEMENT p (#PCDATA | italics | bold)*>
> <!ELEMENT italics (#PCDATA)>
> <!ELEMENT bold (#PCDATA)>
> ...
>
> And thus
>
> <p> This <italics>contains</italics> <bold>embedded</bold> child.</p>
>
> Is this posible with W3C XML schema?  If so, it would be highly
> appreciated if someone could provide an example of a complexType that
> can handle this.

Sure, it's very simple. You just have to set the attribute mixed="true" on
the complexType definition.
Example:

<xs:complexType name="pType" mixed="true">
   <xs:sequence>
      <xs:element name="italics" type="xs:string"/>
      <xs:element name="bold" type="xs:string"/>
   </xs:sequence>
</xs:complexType>

Note that in W3C XML Schema the child elements occurence constraints and
order will still be preserved so in the above complexType the child
elements italics and bold must appear in that order and only once. If you
want the same semantics as in the DTD you'll have to do like this:

<xs:complexType name="pType" mixed="true">
   <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="italics" type="xs:string"/>
      <xs:element name="bold" type="xs:string"/>
   </xs:choice>
</xs:complexType>

Cheers,
/Eddie

>
>
> Thanks kindly,
> Richard.
Received on Tuesday, 12 February 2002 04:11:11 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:26 GMT