This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 2222 - R-230: Question on maxOccurs=0, particles and restriction
Summary: R-230: Question on maxOccurs=0, particles and restriction
Status: CLOSED FIXED
Alias: None
Product: XML Schema
Classification: Unclassified
Component: Structures: XSD Part 1 (show other bugs)
Version: 1.1 only
Hardware: All All
: P4 normal
Target Milestone: ---
Assignee: C. M. Sperberg-McQueen
QA Contact: XML Schema comments list
URL:
Whiteboard: medium, easy, restriction cluster
Keywords: resolved
Depends on:
Blocks:
 
Reported: 2005-09-14 19:22 UTC by Sandy Gao
Modified: 2009-04-21 19:21 UTC (History)
0 users

See Also:


Attachments

Description Sandy Gao 2005-09-14 19:22:42 UTC
Please clarify an issue regarding the use of maxOccurs="0", particularly within 
a type derived by <restriction> 

From various places in the Structures recommendation I have gathered the 
following information: 

1. Where minOccurs=maxOccurs=0, the item "corresponds to no component at all." 
[repeated] 

2. The Particle Schema Component: {max occurs} - "Either a non-negative integer 
or unbounded." http://www.w3.org/TR/xmlschema-1/#p-max_occurs 

3. Particle Correct: for all particles "{max occurs} must be greater than or 
equal to 1." http://www.w3.org/TR/xmlschema-1/#p-props-correct 

Also, from the Primer: 

4. An element with minOccurs="0" and maxOccurs="0" means the element "must not 
appear." http://www.w3.org/TR/xmlschema-0/#cardinalityTable 

5. In restriction, minOccurs="0" and maxOcurs="0" means "exclusion of an 
optional component." http://www.w3.org/TR/xmlschema-0/#restrictsTable 

It seems to me that (2) and (3) conflict. (2) effectively says that a particle 
may have maxOccurs="0" while (3) says this would not be a correct particle. Is 
an incorrect particle still a particle?? I'm not sure that (1) excuses this 
conflict. Looking at the Errata I cannot see any substantive changes to these 
definitions. 

The problem I have specifically relates to restriction of a complexType 
containing a sequence. As I understand it, the derived restricted sequence can 
either simply not mention the element I wish to 'prohibit' or can explicitly 
prohibit it by specifying maxOccurs="0" and this should mean the same thing. 
However, (3) implies that the latter would not validate. 

E.g.

   <complexType name="base">
     <sequence>
       <element name="a" minOccurs="0" maxOccurs="1"/>
       <element name="b" minOccurs="0" maxOccurs="1"/>
       <element name="c" minOccurs="0" maxOccurs="1"/>
     </sequence>
   </complexType>

   <complexType name="deriveByOmission">
     <complexContent>
       <restriction base="base">
         <sequence>
           <element name="a" minOccurs="0" maxOccurs="1"/>
           < prohibit element "b" by omission -->
           <element name="c" minOccurs="0" maxOccurs="1"/>
         </sequence>
       </restriction>
     </complexContent>
   </complexType>

   <complexType name="deriveByZeroOccurrence">
     <complexContent>
       <restriction base="base">
         <sequence>
           <element name="a" minOccurs="0" maxOccurs="1"/>
           <element name="b" minOccurs="0" maxOccurs="0"/> <!-- prohibit
element "b" -->
           <element name="c" minOccurs="0" maxOccurs="1"/>
         </sequence>
       </restriction>
     </complexContent>
   </complexType>

(Helpfully, of the seven schema tools I've tried, 5 accept both derivations 
(but given other experiences are maybe just too lax) and 2 refuse both...) 

Which of these 2 derivations are correct?

See:
http://lists.w3.org/Archives/Public/www-xml-schema-comments/2003JulSep/0042.html
Comment 1 Sandy Gao 2006-11-22 04:08:46 UTC
Both derivation should be valid. "deriveByOmission" and "deriveByZeroOccurrence" will have the same content model, because minOccurs=maxOccurs=0 "corresponds to no component at all."

#2 and #3 are confusing.

Proposal: to change the component description and disallow "0" as a valid value for maxOccurs. And to remove "{max occurs} must be greater than or equal to 1" from "Particle Correct".

Resolution: adopted at 2006-11-17 telecon.