Page 1 of 1

<sequence>, <all>, or <choice>?

Posted: Mon Dec 26, 2005 11:46 pm
by jsb
I've defined an element that contains other elements. As far as I am concerned, the contained elements may appear in any order. The ixx, iyy, and izz elements are required and must appear once. The ixz, ixy, and iyz elements are each optional, and may appear once each. The ptmass element may or may not appear at all - and it may appear any number of times. I haven't yet been able to figure out how I can write a schema for this.

Right now, I've got this:

Code: Select all


<xs:complexType>
<xs:all>
<xs:element ref="ixx" minOccurs="1"/>
<xs:element ref="iyy" minOccurs="1"/>
<xs:element ref="izz" minOccurs="1"/>
<xs:element ref="ixy"/>
<xs:element ref="ixz"/>
<xs:element ref="iyz"/>
<xs:element ref="emptywt" minOccurs="1"/>
<xs:element ref="location" minOccurs="1"/>
<xs:element ref="ptmass" minOccurs="0" maxOccurs="unbounded"/>
</xs:all>
</xs:complexType>
This is problematic, only because I cannot specify the pointmass object as occurring any number of times.

Do I have any alternatives? The <sequence> item would work, except that the contained elements can appear in any order.

Jon

Posted: Thu Dec 29, 2005 11:04 am
by george
Hi Jon,

The default values for minOccurs and maxOccurs are 1 in both cases so you did not make the ixz, ixy, and iyz optional, you need to add a minOccurs="0" to have them optional. The problem is that 0 and 1 are the only values allowed for minOccurs/maxOccurs inside an all content model so you cannot say that some element can appear any numer of times.

As always, the solutions are to specify an order using sequence or create a more relaxed model for instance using choice and eventually enforce your constraints using Schematron embedded rules or at the application level.

Best Regards,
George