Re: key/keyref and default attributes

Hi Alison,

> Can an attribute with a specified default be a keyref? When I try to
> validate the following example instance document with XML Spy, I get
> this error message:
>
> Undefined values for keyref identity constraint
> 'patternForegroundColorRef' - the values referred to in the field
> selector must match an existing unique/key value.
>
> I take this to mean that if I specify an attribute as a keyref, it
> is required in the instance document?

The XML Schema spec specifically says:

 "NOTE: The use of [schema normalized value] in the definition of key
  sequence above means that default or fixed value constraints may
  play a part in key sequences."

It's absolutely fine to specify a defaulted attribute as a keyref.
Your document is valid according to both Xerces and MSXML. The error
that you're getting in XML Spy is due to a bug in its schema
validator -- I suggest you send a bug report and start using Xerces or
MSXML as your schema validator as they are generally a lot more
conformant.

If you have to stick to XML Spy, note that the other constraints that
you've used in your schema mean that you don't actually need the
keyref for validation. You have to have eight colors in your
colorTable; they have to have different values for their index
attributes due to the colorKey; and those values of the index
attributes have to be the integers between 0 and 7. Therefore the fact
that the foregroundColor and backgroundColor attributes have to have
integer values between 0 and 7 automatically constrains them to
pointing to one of the colors.
  
Cheers,

Jeni

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

Received on Tuesday, 27 May 2003 12:03:43 UTC