RE: Choice

Andrew:

My interpretation -

"choice" content model is used to indicate that only one element of the
given list of elements MUST appear.
So, if more than one element appears or no elements appear, both of this are
invalid conditions.

Also, in "<xsd:choice minOccurs="0" maxOccurs="unbounded">" - minOccurs
refer to entire "choice" group as opposed to elements within the choice. So
the entire choice group may not occur at all. And that's perfectly valid.

So, if you want to say - "none of the elements have to be used but ANY ONE
of them
can be used as many times as needed", you will probably have to express as
below -

<choice>
  <element ref="A" minOccurs="0" maxOccurs="unbounded"/>
  <element ref="C" minOccurs="0" maxOccurs="unbounded"/>
  <element ref="D" minOccurs="0" maxOccurs="unbounded"/>
</choice>

I have tested this with XML Spy and it works !!

--Naren




-----Original Message-----
From: xmlschema-dev-request@w3.org
[mailto:xmlschema-dev-request@w3.org]On Behalf Of Andrew Wilson
Sent: Thursday, February 21, 2002 5:04 PM
To: 'XMLDev'
Subject: Choice


Hi

I'm new to XML schema development so my question might be really simple and
have been answered years ago:)

In the XML Schema Spec. part 1 it says in sect. 3.8.1: "...(choice)
correspond to exactly one of the specified particles;". I read this as
saying one of the particles in the choice group *must* appear.

However, the XML representation summary in 3.8.2 allows a minOccurs for
choice of 0 (nonNegativeInteger). So is the following valid?:

<xsd:choice minOccurs="0" maxOccurs="unbounded">
 <xsd:element ref="A"/>
 <xsd:element ref="B"/>
 <xsd:element ref="C"/>
 <xsd:element ref="D"/>
 <xsd:element ref="E"/>
 <xsd:element ref="F"/>
 <xsd:element ref="G"/>
</xsd:choice>

[I'm trying to say that none of the elements have to be used but any of them
can be used as many times as needed]

If this is correct, how should the statement in 3.8.1 be read?
Thanks.

Andrew Wilson

Received on Thursday, 7 March 2002 18:39:00 UTC