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 3996 - R-230: Question on maxOccurs=0, particles and restriction
Summary: R-230: Question on maxOccurs=0, particles and restriction
Status: NEW
Alias: None
Product: XML Schema
Classification: Unclassified
Component: Structures: XSD Part 1 (show other bugs)
Version: 1.0 only
Hardware: All Windows 3.1
: P2 normal
Target Milestone: ---
Assignee: David Ezell
QA Contact: XML Schema comments list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-22 04:22 UTC by Sandy Gao
Modified: 2012-12-04 00:50 UTC (History)
0 users

See Also:


Attachments

Description Sandy Gao 2006-11-22 04:22:41 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