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

minOccurs dependent on other element value / xpath

From: Neff, Sam [NEA] <SNeff@nea.org>
Date: Tue, 25 Jun 2002 09:12:50 -0400 (EDT)
Message-ID: <3A0619C996057D42B5326351A04CEA373AAB24@NEA-HQ-S4.NEA.LOC>
To: <xmlschema-dev@w3.org>




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:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
   <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>
</xs:schema>


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.

Is there any way to accomplish this in XML Schema?

Thanks,

Samuel Neff



*******************************************************************
Only the individual sender is responsible for the content of the
message, and the message does not necessarily reflect the position
or policy of the National Education Association or its affiliates.
Received on Tuesday, 25 June 2002 09:34:55 GMT

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