Re: keyrefs

Hi Gary,

> I've migrated to using Schematron instead (thank you Jeni
> Tennison for saving me from more XML schema hell).

Oh that's right - name and shame ;)

> It means that I've had to add an extra XSLT sylesheet processing
> stage to my parser but at least I get the full power of xpath and
> the ability to define your own error messages. I can also put in
> more complex constraints like "I want this attribute to be present
> or this attribute to be present but not both" or "I want this
> attribute to be a key but I want it to be optional" or "if element X
> is present then element Y must be present otherwise if must be
> absent".

Trying to redeem myself, I think you can probably do the latter two in
XML Schema.

If you want an attribute holding an key value to be optional, you can
use a unique identity constraint rather than a key identity
constraint. The unique identity constraint works in exactly the same
way as the key identity constraint (you can still refer to it with a
keyref) except that it doesn't force there to be a value of every
selected element in the schema.

The fact that element X and Y go together is (I think) a matter of
writing the desired content model, which should be something that XML
Schema is good at.

Actually RELAX NG is pretty good at the co-occurrence stuff - this
attribute or another attribute, this attribute or this element, 3
occurrences of this element but mixed in any order. Schematron really
comes into its own, I think, when it's comparing values.

Cheers,

Jeni

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

Received on Friday, 9 November 2001 05:56:15 UTC