Re: Problem with sequence inside a group

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:sequence>
    <xs:element ref="Menu" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element ref="Separator" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element ref="Action" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:group>

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:choice>
    <xs:element ref="Menu" />
    <xs:element ref="Separator" />
    <xs:element ref="Action" />
  </xs:choice>
</xs:group>

In other words, rather than having:

  (Menu*, Separator*, Action*)*

you'd have:

  (Menu | Separator | Action)*

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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