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

Re: Attribute groups

From: Jeni Tennison <jeni@jenitennison.com>
Date: Fri, 15 Mar 2002 10:00:22 +0000
Message-ID: <171178967721.20020315100022@jenitennison.com>
To: "Snow, Corey" <CSNOW@ddpwa.com>
CC: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Hi Corey,

> What I'd like to be able to do is make the attribute *group*
> optional, based on whether one of the attributes in the group (the
> required one) is supplied- in other words, if the attrOne attribute
> is supplied, an attrTwo attribute may optionally be supplied. If
> attrOne is not supplied, attrTwo CANNOT be supplied, but the
> document remains valid if neither is supplied.

What you're describing is a "co-occurrence constraint" in which the
presence of one attribute affects whether the presence of another
attribute is allowed.

XML Schema is notoriously bad at co-occurrence constraints. The usual
advice in this situation would be to do one of the following:

  - Express the distinct attribute combinations as separate complex
    types both derived from the same abstract complex type; make the
    element have the abstract type as its type; use the xsi:type
    attribute to identify which of the two types is being used in the
    particular instance. (Note that this involves changing the look of
    your XML instance documents.)

  - Express as much as you can in XML Schema, then use Schematron or
    another schema adjunct to express the co-occurrence constraint.

If you want more details on either of these options, let us know.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Friday, 15 March 2002 05:00:24 GMT

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