[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: using the maxOccurs contruct with sequences.

From: Jeff Rafter <lists@jeffrafter.com>
Date: Mon, 14 Mar 2005 09:10:08 -0800
Message-ID: <4235C570.2030109@jeffrafter.com>
To: Ken_Gross@Countrywide.Com
CC: xmlschema-dev@w3.org
xs sequence maxoccurs

> In the following example, there are two representations of an unbounded 
> sequence of elements in  "ReportOptionsModel".   Is the first 
> representation ever justified?  If it is, when should it be used?

Hi Ken,

With a single element in the sequence (as you have in each example) it 
is really up to you or the preference of the users of your XML Schema. 
When working with multiple elements in the sequence though, the 
difference is important:

         <xs:complexType name="ReportOptionsModel">
           <xs:sequence maxOccurs="unbounded">
             <xs:element name="FilterA"/>
             <xs:element name="FilterB"/>
           </xs:sequence>
         </xs:complexType>

         <xs:complexType name="ReportOptionsModel2">
           <xs:sequence>
             <xs:element name="FilterA" maxOccurs="unbounded"/>
             <xs:element name="FilterB" maxOccurs="unbounded"/>
           </xs:sequence>
         </xs:complexType>

In the first case, the instance might have:

   <FilterA/>
   <FilterB/>
   <FilterA/>
   <FilterB/>
   <FilterA/>
   <FilterB/>
   ...

In the second case it would be:

   <FilterA/>
   <FilterA/>
   <FilterA/>
   <FilterA/>
   <FilterB/>
   <FilterB/>
   ...

Where all of the FilterA elements would appear before all of the FilterB 
elements.

In XML Schemas where you have some sequences with only a single element 
another consideration is how the document will be modified in subsequent 
versions. If it is your anticipation that more elements will be added to 
the sequence at a later date (and you are indifferent to the order shown 
above) then I would place it on the containing <xs:sequence>. In all 
other cases I would place the cardinality constraint on the 
<xs:element>. That is just my taste though, I prefer to have the 
cardinality constraint as close to the thing it constrains as possible.

All the best,
Jeff Rafter
Received on Monday, 14 March 2005 17:10:43 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.