Dynamic minOccurs

From W3C Wiki
Jump to: navigation, search

Dynamic minOccurs (a co-constraint use case)

Adjust minOccurs of a complex type, based on the value of an element occurring earlier in the document (here: a Boolean value controling a conditional expression for minOccurs).

Cf. Fixed occurrence count, which specifies minOccurs and maxOccurs directly in the instance.

source: Sam Neff [1]


Other use cases: Co-constraint Use Cases

Description

   Is it possible to specify minOccurs dynamically; dependent on the
   value of an element in the schema instance?
   For example, if I have two XML documents:


    <package>
       <header>
          <name>2001-02 Boise</name>
          <isFinal>1</isFinal>
       </header>
       <plans>
          <plan>some plan</plan>
       </plans>
    </package>


   And


    <package>
       <header>
          <name>2001-02 Boise</name>
          <isFinal>0</isFinal>
       </header>
       <plans/>
    </package>


   With a corresponding schema:


       <xs:element name="package">
          <xs:complexType>
             <xs:all>
                <xs:element name="header">
                   <xs:complexType>
                      <xs:all>
                         <xs:element name="name" type="xs:string"/>
                         <xs:element name="isFinal" type="xs:boolean"/>
                      </xs:all>
                   </xs:complexType>
                </xs:element>
                <xs:element name="plans" minOccurs="0">
                   <xs:complexType>
                      <xs:sequence>
                         <xs:element
                            name="plan"
                            type="xs:anyType"
                            minOccurs="0"
                            maxOccurs="unbounded"/>
    
                            <!-- I want minOccurs to be 1 when
                                 /package/header/isFinal=1 -->
    
                      </xs:sequence>
                   </xs:complexType>
                </xs:element>
             </xs:all>
          </xs:complexType>
       </xs:element>


   The minOccurs="0" on element "plan".  In cases where the value of element
   "isFinal" (package/header/isFinal) is true, I want minOccurs on "plan" to be 1.

Analysis

(Add your analysis here; see your name in pixels!)

Possible solutions

Relax NG

Schematron

Check clause

SchemaPath

Conditional Type