RE: Choice

I would recommend using wrapping elements on the tags you want to repeat, so
your XML would look like this, if you want only child3 to repeat:
<?xml version="1.0" encoding="UTF-8"?>
<root>
	<child1/>
	<child2/>
	<children3>
		<child3/>
		<child3/>
	</children3>
</root>

This can be expressed like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="root">
		<xs:complexType>
			<xs:all>
				<xs:element name="child1" minOccurs="0"/>
				<xs:element name="child2"/>
				<xs:element name="children3"
type="Children3Type"/>
			</xs:all>
		</xs:complexType>
	</xs:element>
	<xs:complexType name="Children3Type">
		<xs:sequence>
			<xs:element name="child3" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>

This isn't using the exact structure you were going for, but it solves the
problem...assuming you have controller of the parsing.

-Nathan

-----Original Message-----
From: Piccand Régis [mailto:regis.piccand@imtf.ch]
Sent: Friday, March 08, 2002 9:00 AM
To: 'Beyer,Nathan'; Schema Dev XML (E-mail)
Subject: RE: Choice


Sure ...

test1.xml and test1.xsd, using "all"

child1, child2 and child3 can be in any order. Child1 is optional, child2 is
mandatory, but child3 cannot be repeated (maxOccurs must be "1" in "all")


test2.xml and test2.xsd, using "sequence"
child1 is optional but not repeatable, child2 is optional and repeatable,
child3 is mandatory and not repeatable. But they must be ordered as defined
in the schema (child1, then child2, then child3)


test3.xml and test3.xsd, using "choice"
Whatever minOccurs and maxOccurs are set to for "childx", it is the "choice"
minOccurs and maxOccurs that is used ...

Best regards,

Régis




-----Original Message-----
From: Beyer,Nathan [mailto:NBEYER@cerner.com]
Sent: vendredi, 8. mars 2002 15:42
To: Schema Dev XML (E-mail)
Subject: RE: Choice


Do you have a couple of examples that we can look at?

-----Original Message-----
From: Piccand Régis [mailto:regis.piccand@imtf.ch]
Sent: Friday, March 08, 2002 8:11 AM
To: 'Beyer,Nathan'; Schema Dev XML (E-mail)
Subject: RE: Choice


Hello,

Here is my contribution to making things more confused ...

I'm trying to have an unordered list of elements that can be "mandatory OR
optional" AND repeatable (i.e. elements are unordered and "MinOccurs" and
"MaxOccurs" must be specified for each element).

Using "All", maxoccurs is bound to 1 (optional but not repeatable). Using
"sequence", elements are ordered (optional and repeatable). Using "choice",
elements are optional (repeatable but not mandatory).

Is there a possibility to achieve what I'm trying to do ?

Thanks in advance and sorry for making things worse ;-) ...

Régis Piccand


-----Original Message-----
From: Beyer,Nathan [mailto:NBEYER@cerner.com]
Sent: vendredi, 8. mars 2002 14:59
To: Schema Dev XML (E-mail)
Subject: RE: Choice


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.

-Nathan

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


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

CONFIDENTIALITY NOTICE

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 Friday, 8 March 2002 10:17:28 UTC