- 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>
Sam, 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: documentation>... Bob 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> cc: 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: <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 16:27:57 UTC