Re: pair interactions in XML schema

Bob Schloss wrote:
> The second one, which will be part of the definition of the element
> which contains all the acquaintance elements (and possibly all the
> person elements also), will say that the concatenation of all fields
> person/@name within selector acquaintance must be unique. (I'm not
> 100% certain that naming a single field when that element/particle
> (person) is declared minOccurs="2" maxOccurs="2" actually does
> this.).

I don't think that it's possible to express this in XML Schema,
because of the rule that the fields of identity constraints must only
select one information item. If the identity constraint was expressed
as:

  <xs:key name="acquaintances">
    <xs:selector xpath="acquaintance" />
    <xs:field xpath="person/@name" />
  </xs:key>

then the field would select two name attributes and therefore be
invalid. If XML Schema allowed positional predicates, you could use:

  <xs:key name="acquaintances">
    <xs:selector xpath="acquaintance" />
    <xs:field xpath="person[1]/@name" />
    <xs:field xpath="person[2]/@name" />
  </xs:key>

but it doesn't, so you can't.

I think that the only way around is to make each acquaintance hold
differently named child elements (e.g. person1 and person2) and then
use:

  <xs:key name="acquaintances">
    <xs:selector xpath="acquaintance" />
    <xs:field xpath="person1/@name" />
    <xs:field xpath="person2/@name" />
  </xs:key>

although that isn't perfect, for the reasons Bob points out:

> However, this second <unique) will not enforce your condition
> *unless* your documents always specify the two child elements of
> acquaintance in some fixed order, such as the person whose name is
> lowest in alphabetical order always comes first, or the person which
> appears in the person elements order comes first. (And there's no
> way to tell a validator to check that).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Monday, 17 June 2002 05:22:52 UTC