key/keyref and default attributes

Hi,

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?

Example schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:simpleType name="ColorTableIndexType">
		<xs:restriction base="xs:integer">
			<xs:minInclusive value="0"/>
			<xs:maxExclusive value="8"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ColorHexType">
		<xs:restriction base="xs:string">
			<xs:pattern value="0x[A-F0-9]{2}"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="color">
		<xs:complexType>
			<xs:attribute name="index" type="ColorTableIndexType" use="required"/>
			<xs:attribute name="r" type="ColorHexType" use="required"/>
			<xs:attribute name="g" type="ColorHexType" use="required"/>
			<xs:attribute name="b" type="ColorHexType" use="required"/>
		</xs:complexType>
	</xs:element>
	<xs:element name="colorTable">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="color" minOccurs="8" maxOccurs="8"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="pattern">
		<xs:complexType>
			<xs:attribute name="name" type="xs:string"/>
			<xs:attribute name="foregroundColor" type="ColorTableIndexType" use="optional" default="1"/>
			<xs:attribute name="backgroundColor" type="ColorTableIndexType" use="optional" default="0"/>
		</xs:complexType>
	</xs:element>
	<xs:element name="patternTable">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="pattern" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="drawing">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="colorTable"/>
				<xs:element ref="patternTable"/>
			</xs:sequence>
		</xs:complexType>
		<xs:key name="colorKey">
			<xs:selector xpath="colorTable/color"/>
			<xs:field xpath="@index"/>
		</xs:key>
		<xs:keyref name="patternForegroundColorRef" refer="colorKey">
			<xs:selector xpath="patternTable/pattern"/>
			<xs:field xpath="@foregroundColor"/>
		</xs:keyref>
		<xs:keyref name="patternBackgroundColorRef" refer="colorKey">
			<xs:selector xpath="patternTable/pattern"/>
			<xs:field xpath="@backgroundColor"/>
		</xs:keyref>
	</xs:element>
</xs:schema>

Example instance:
<?xml version="1.0" encoding="UTF-8"?>
<drawing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="drawing_schema.xsd">
	<colorTable>
		<color index="0" r="0x00" g="0x00" b="0x00"/>
		<color index="1" r="0xFF" g="0xFF" b="0xFF"/>
		<color index="2" r="0xFF" g="0x00" b="0x00"/>
		<color index="3" r="0x00" g="0xFF" b="0x00"/>
		<color index="4" r="0x00" g="0x00" b="0xFF"/>
		<color index="5" r="0xFF" g="0xFF" b="0x00"/>
		<color index="6" r="0xFF" g="0x00" b="0xFF"/>
		<color index="7" r="0x00" g="0xFF" b="0xFF"/>
	</colorTable>
	<patternTable>
		<pattern name="foo" foregroundColor="2" backgroundColor="4"/>
		<pattern name="bar"/>
	</patternTable>
</drawing>

Thanks,
Alison Meynert

--
alisonm@schemasoft.com
Developer
Schema Software, Inc.
http://www.schemasoft.com

Received on Monday, 26 May 2003 14:41:16 UTC