W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2002

RE: xs:all - why is minOccurs, maxOccurs restricted to "0" or "1" for child xs:element ?

From: <dbowen@es.com>
Date: Thu, 28 Mar 2002 14:24:59 -0700
Message-ID: <AFE3FBA300B6F04282BE07949DB2E123A4184F@TORINO.corp.es.com>
To: <jeni@jenitennison.com>
Cc: <xmlschema-dev@w3.org>
Thanks Jeni, you're great!

>> The problem is that minOccurs and maxOccurs for <xs:element> under
>> <xs:all> have to be "0" or "1". It seems that the Schema's
>> definition of <xs:group name="allModel"> ... is the part that's
>> placing this restriction. Is there some fundamental reason why
>> <xs:all> places such restrictions on the child element's minOccurs
>> and maxOccurs? Or is there another way to define the schema to have
>> the same effect that I'm after?
>
>There's no way of expressing the constraints that you're after on a
>content model using XML Schema alone. I'm not sure about the rationale
>for this restriction, but I think it's something to do with the
>semantics of an xs:all that contains particles with a maxOccurs
>greater than one being ambiguous (does it mean that the elements of
>the same type have to be next to each other or not? - in your case
>not, in other cases it does).

Good point. For XML Schema 1.0, its obviously too late.
But for 1.1 or 2.0, perhaps a new attribute on xs:all
could solve the ambiguity (maybe "groupSameType" as a Boolean),
or even letting xs:sequence and/or xs:choice also be children to
force grouping of the same type. I think that this would make
it more flexible and still unambiguous, but it certainly might
be much harder to implement for a validator.


>There are two approaches that you could consider:
>
>  - defining the schema to give a canonical ordering, and then having
>    a script or stylesheet that reorders the instance documents into
>    that canonical ordering prior to validation
>
>  - defining the schema to give a loose definition of the content
>    model (e.g. any number in any order) and then add rules using
>    Schematron or another schema language to express the limitations
>    on their occurrence

For XMLSchema 1.0, these certainly sound like the best options!
I especially like the 2nd option.  If I keep the Schema in a DOM,
I could add a new namespace and throw in my "desired" maxOccurs
as an attribute in that namespace like so:

 <xs:choice minOccurs="0" maxOccurs="unbounded" xs-ext:useExtendedInfo="true">
  <xs:element ref="e1" minOccurs="0" maxOccurs="unbounded" xs-ext:maxOccurs="2"/>
  ...
 </xs:choice>

If I use a SOM, I'd have to do something else, but you've given me some
good ideas.

Thanks!

-Daniel
Received on Thursday, 28 March 2002 16:25:36 GMT

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