W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2001

Re: Order of elements in a complex-type

From: Jeni Tennison <jeni@jenitennison.com>
Date: Sat, 1 Dec 2001 13:39:20 +0000
Message-ID: <7088925698.20011201133920@jenitennison.com>
To: "Mason Lee" <mgl@netspace.org>
CC: xmlschema-dev@w3.org, erik.beijnoff@addsystems.com, 2kseema@sun20.datamatics.com
Hi Mason,

> Hi all! I saw Erik Beijnoff's good answer to the above question in a
> recent thread. I wonder further, however, how could this complex
> type be defined such that the elements "TextBox" and "TextArea" may
> appear any number of times, but the element "Header" must appear
> only once, and while retaining the interesting characteristic that
> any of these three clild elements may appear in any order. Any
> ideas?

Assuming that you don't care if the TextBox and TextArea elements are
intermingled, and there's no minimum number of occurrences of TextBox
and TextArea, you could use the following:

<xs:complexType name="FormType">
  <xs:sequence>
    <xs:group ref="TextBoxOrTextArea" minOccurs="0"
              maxOccurs="unbounded" />
    <xs:element name="Header" type="HeaderType" />
    <xs:group ref="TextBoxOrTextArea" minOccurs="0"
              maxOccurs="unbounded" />
  </xs:sequence>
</xs:complexType>

<xs:group name="TextBoxOrTextArea">
  <xs:choice>
    <xs:element name="TextBox" type="TextBoxType" />
    <xs:element name="TextArea" type="TextAreaType" />
  </xs:choice>
</xs:group>

(Using a group so that you only have to declare TextBox and TextArea
once.)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Saturday, 1 December 2001 09:05:03 GMT

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