W3C home > Mailing lists > Public > xmlschema-dev@w3.org > July 2004

Re: Problem with sequence inside a group

From: Jeni Tennison <jeni@jenitennison.com>
Date: Fri, 23 Jul 2004 16:42:36 +0100
Message-ID: <1771226326.20040723164236@jenitennison.com>
To: "Simon Kampa" <simon.kampa@stasys.co.uk>
Cc: xmlschema-dev@w3.org

Hi Simon,

> Xerces 2.5.2 complains at my schema when a sequence (directly under
> a group declaration) has cardinality values (see Listing 1). To me
> this appears to be a bug within the schema parser. What do you lot
> think?

Xerces is correct. The particles directly within a <xs:group>
definition must not have occurrence constraints on them: those should
instead be specified on the *reference* to the group.

(Don't ask me why this is so, it just is.)

> As a work-around, I simply added a choice around the sequence
> (Listing 2) and it works.

Yeah, crazy innit. The correct "workaround" is to have:

<xs:group name="MenuGroup">
    <xs:element ref="Menu" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element ref="Separator" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element ref="Action" minOccurs="0" maxOccurs="unbounded"/>

and then, whenever you use the group to have:

  <xs:group ref="MenuGroup" minOccurs="0" maxOccurs="unbounded" />

BTW, the usual pattern for a content model in which any of the
elements can appear, in any order, any number of times, would be to
use a <xs:choice> rather than a <xs:sequence> and remove the
occurrence constraints from the individual element particles, as in:

<xs:group name="MenuGroup">
    <xs:element ref="Menu" />
    <xs:element ref="Separator" />
    <xs:element ref="Action" />

In other words, rather than having:

  (Menu*, Separator*, Action*)*

you'd have:

  (Menu | Separator | Action)*



Jeni Tennison
Received on Friday, 23 July 2004 11:42:44 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:22 UTC