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

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 UTC