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

Re: minOccurs dependent on other element value / xpath

From: Bob Schloss <rschloss@us.ibm.com>
Date: Tue, 25 Jun 2002 16:26:47 -0400
To: "Neff, Sam [NEA]" <SNeff@nea.org>, xmlschema-dev@w3.org
Message-ID: <OF6065414F.27E15095-ON85256BE3.006FE729@us.ibm.com>


There is no way to do what you seek using only W3C XML Schema Language 1.0.

If you are willing to use a different element name for package when isFinal
is 1 or isFinal is 0, you could do specify this.

If you are willing to use xsi:type="..." on the package element, and have 2
complexTypes, one of which is derived from the other, and one of which
requires at least one <plan> and the other doesn't, then you can do this.

However, both of these proposals require some change to the format of your
instance document.

If you are not interested in a validator enforcing this rule, but simply
want to communicate it to developers who write software that emits or
receives instance documents, you can document this via <xs:annotation><xs:


Extensible Technologies
IBM Thomas J. Watson Research Center
Yorktown Heights, NY, USA

"Neff, Sam [NEA]" <SNeff@nea.org>@w3.org on 06/25/2002 09:12:50 AM

Sent by:    xmlschema-dev-request@w3.org

To:    <xmlschema-dev@w3.org>
Subject:    minOccurs dependent on other element value / xpath

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:

      <name>2001-02 Boise</name>
      <plan>some plan</plan>


      <name>2001-02 Boise</name>

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:element name="header">
                     <xs:element name="name" type="xs:string"/>
                     <xs:element name="isFinal" type="xs:boolean"/>
            <xs:element name="plans" minOccurs="0">


                        <!-- I want minOccurs to be 1 when
                             /package/header/isFinal=1 -->


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?


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 16:27:57 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:57 UTC