Re: Mixed content

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 UTC