W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > July to September 2003

maxOccurs="0"

From: Daplyn, Tim <Tim.Daplyn@eu.sony.com>
Date: Thu, 14 Aug 2003 07:02:24 -0700
Message-Id: <5.1.0.14.1.20030814070219.028797c0@localhost>
To: W3C XML Schema Comments list <www-xml-schema-comments@w3.org>




Please can someone help clarify an issue for me 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) & (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...)

Please can someone suggest which of these 2 derivations are correct and/or
best practice?


Many thanks,
Tim Daplyn



*************************************************************************
The information contained in this message or any of its
attachments may be privileged and confidential and intended
for the exclusive use of the addressee. If you are not the
addressee any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited
*************************************************************************
Received on Thursday, 14 August 2003 09:02:41 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 6 December 2009 18:13:02 GMT