W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2007

Re: xs:choice question

From: <noah_mendelsohn@us.ibm.com>
Date: Wed, 27 Jun 2007 15:51:49 -0400
To: "Markus Gamperl" <markus.gamperl@gmx.at>
Cc: xmlschema-dev@w3.org, xmlschema-dev-request@w3.org
Message-ID: <OF0042AD14.BF143CE8-ON85257307.006C8213-85257307.006CE414@lotus.com>

If the order of a and b doesn't matter, then:


<xs:all>
 <xs:element name="a" type="xs:string" minOccurs="0"/>
 <xs:element name="b" type="xs:string" minOccurs="0"/>
</xs:all>

If when both are present, the "a" must come first:

<xs:sequence>
 <xs:element name="a" type="xs:string" minOccurs="0"/>
 <xs:element name="b" type="xs:string" minOccurs="0"/>
</xs:sequence>

The reason for the editor error in your model is that when an <a> shows up 
as the first element in your instance, a parser can't know with out 
looking further into the document whether to match the first or second 
reference to "a" in your content model.  Schemas that raise such 
challenges violate what the Schema Recommendation calls the Unique 
Particle Attribution constraint, or in the terms of the error message, are 
to some degree nondeterministic.  Anyway, your schema is not a legal one, 
which is why the editor is complaining.

Noah

--------------------------------------
Noah Mendelsohn 
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------








"Markus Gamperl" <markus.gamperl@gmx.at>
Sent by: xmlschema-dev-request@w3.org
06/27/2007 03:21 PM
 
        To:     xmlschema-dev@w3.org
        cc:     (bcc: Noah Mendelsohn/Cambridge/IBM)
        Subject:        xs:choice question



Hello!

I have the following xml fragment example:

<data>
 <a>a test</a>
 <b>b test</a>
<data>

the schema should check the following rules (three options):
- element a must exist, b may not
- element b must exist, a may not
- element a and b must exist

Therefor I have defined the following choice:
...
<xs:choice>
 <xs:element name="a" type="xs:string"/>
 <xs:element name="b" type="xs:string"/>
 <xs:sequence>
   <xs:element name="a" type="xs:string"/>
   <xs:element name="b" type="xs:string"/>
 </xs:sequence>
</xs:choice>
...

The xml editor raises an error - something about non determenistic 
declaration...

Do you have a suggestion how to define these three rules?

Thanks for your help!
Markus
-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
Received on Wednesday, 27 June 2007 19:51:39 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:59 GMT