W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2002

Original Choice (was RE: Choice)

From: Naren Chawla <naren_chawla@attbi.com>
Date: Tue, 12 Mar 2002 09:18:27 -0800
To: "Beyer,Nathan" <NBEYER@cerner.com>, "Schema Dev XML \(E-mail\)" <xmlschema-dev@w3.org>
Message-ID: <AOEGLCJGIFANMEODKIBGKEDACCAA.naren_chawla@attbi.com>

I know this discussion drifted in different direction, however, coming back
to original issue.

I tested this solution with Xerces-Java 2.0.1. And it seems to work.

The files -


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="test">
				<xs:element name="t1" type="xs:string" minOccurs="0"
				<xs:element name="t2" type="xs:string" minOccurs="0"

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Now the question I have for schema gurus - Is this correct usage for
"choice" content model ?  XML Spy, TurboXML (Tibco) and Xerces-Java 2 seem
to be okay with this. However, the XSD spec is ambiguous.

>>>> Nathan says:
Also, using <choice minOccurs="0" maxOccurs="unbounded"> will solve the
"none of the elements have to be used but ANY ONE of them can be used as
many times as needed" problem.

Above will work if you define schema as -

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

<choice minOccurs="0" maxOccurs="unbounded">
  <element ref="B" />

-- Naren Chawla

-----Original Message-----
I don't believe the second example given is correct, even though XMLSpy
validates. I'd recommend trying to validate that in Xerces or some other
validator. XMLSpy validates a number of things it shouldn't.

I've always been under the impression that when "choice" is used, all
minOccurs and maxOccurs attribute within the content model are ignored. I've
been trying find proof of this in the spec, but have been unsuccessful so
far. Can anyone confirm or deny this?

Also, using <choice minOccurs="0" maxOccurs="unbounded"> will solve the
"none of the elements have to be used but ANY ONE of them can be used as
many times as needed" problem.

The way I always look at it is the minOccurs and the maxOccurs on the choice
tells you how many times you have to make that choice and/or can make that
choice. In the above case you don't have to make the choice at, but if you
do, you can do so as many times as you want. This could result in choosing
every element within the choice, in any order.

That's my 2 cents.


-----Original Message-----
From: Naren Chawla [mailto:naren_chawla@attbi.com]
Sent: Thursday, March 07, 2002 5:40 PM
To: Andrew Wilson; 'XMLDev'
Subject: RE: Choice


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 -

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

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


-----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


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"/>

[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?

Andrew Wilson

This message and any included attachments are from Cerner Corporation and
are intended only for the addressee. The information contained in this
message is confidential and may constitute inside or non-public information
under international, federal, or state securities laws. Unauthorized
forwarding, printing, copying, distribution, or use of such information is
strictly prohibited and may be unlawful. If you are not the addressee,
please promptly delete this message and notify the sender of the delivery
error by e-mail or you may call Cerner's corporate offices in Kansas City,
Missouri, U.S.A at (+1) (816)221-1024.
Received on Tuesday, 12 March 2002 12:17:42 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:55 UTC