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

Re: element dependencies

From: Eddie Robertsson <eddie@allette.com.au>
Date: Fri, 08 Feb 2002 10:09:37 +1100
Message-ID: <3C630931.7D856CD9@allette.com.au>
To: Marco.Hoendervangers@OVSoftware.com
CC: xmlschema-dev@w3.org
Hi Marco,

> Hi,
> Does anyone knows if it is possible to define dependencies between elements?
> Consider the following xml:
> <person>
>         <name>bill</name>
>         <married>false</married>
> </person>
> When the person is married another element is required: partner.
> <person>
>         <name>bill</name>
>         <married>true</married>
>         <partner>kelly</partner>
> </person>
> Is there a way to define this kind of behaviour in xml schema?

This is commonly known as a co-occurence constraint and these can generally not
be expressed in W3C XML Schema. To express this you can move to another schema
language such as RELAX-NG or Schematron or you can choose to embedd Schematron
rules in your W3C XML Schema.
In this case you could do a workaround by using the xsi:type attribute in your
instance document to define the married type:

<person xsi:type="notMarriedPerson">

<person xsi:type="marriedPerson">

See [1] for more information about embedding Schematron rules and [2] for more
info on xsi:type.


[1] http://lists.w3.org/Archives/Public/xmlschema-dev/2001Nov/0049.html
[2] http://www.w3.org/TR/xmlschema-0/#UseDerivInInstDocs
Received on Thursday, 7 February 2002 17:59:43 UTC

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