Re: Attribute groups

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 UTC