multi-field key/keyref fails to contrain?
Posted: Tue Nov 09, 2004 11:25 pm
Please tell me if I am missing something here. I have a schema with a 2-field key and also a keyref. These are defined at the scope of their common predecessor. The below schema validates with the below instance, when no proper pair of (1,2) exists. Is this a bug or am I thinking wrongheadedly? Thanks.
SCHEMA:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="ConstraintScope">
<xs:complexType>
<xs:sequence>
<xs:element name="Path1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Key1" type="xs:integer"/>
<xs:element name="Key2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path2Parent">
<xs:complexType>
<xs:sequence>
<xs:element name="Path2Child" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FKey1" type="xs:integer"/>
<xs:element name="FKey2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="Path1Keys">
<xs:selector xpath="Path1"/>
<xs:field xpath="Key1"/>
<xs:field xpath="Key2"/>
</xs:key>
<xs:keyref name="Path2KeyRef" refer="Path1Keys">
<xs:selector xpath="Path2Parent/Path2Child"/>
<xs:field xpath="FKey1"/>
<xs:field xpath="FKey2"/>
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
INSTANCE DOC:
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="KeyConstraints.xsd">
<ConstraintScope>
<Path1>
<Key1>1</Key1>
<Key2>1</Key2>
</Path1>
<Path1>
<Key1>2</Key1>
<Key2>2</Key2>
</Path1>
<Path2Parent>
<Path2Child>
<FKey1>1</FKey1>
<FKey2>2</FKey2>
</Path2Child>
<Path2Child>
<FKey1>2</FKey1>
<FKey2>2</FKey2>
</Path2Child>
</Path2Parent>
</ConstraintScope>
</Root>
The first Path2Parent/Path2Child sequence should not validate should it?!?
SCHEMA:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="ConstraintScope">
<xs:complexType>
<xs:sequence>
<xs:element name="Path1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Key1" type="xs:integer"/>
<xs:element name="Key2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Path2Parent">
<xs:complexType>
<xs:sequence>
<xs:element name="Path2Child" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FKey1" type="xs:integer"/>
<xs:element name="FKey2" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="Path1Keys">
<xs:selector xpath="Path1"/>
<xs:field xpath="Key1"/>
<xs:field xpath="Key2"/>
</xs:key>
<xs:keyref name="Path2KeyRef" refer="Path1Keys">
<xs:selector xpath="Path2Parent/Path2Child"/>
<xs:field xpath="FKey1"/>
<xs:field xpath="FKey2"/>
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
INSTANCE DOC:
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="KeyConstraints.xsd">
<ConstraintScope>
<Path1>
<Key1>1</Key1>
<Key2>1</Key2>
</Path1>
<Path1>
<Key1>2</Key1>
<Key2>2</Key2>
</Path1>
<Path2Parent>
<Path2Child>
<FKey1>1</FKey1>
<FKey2>2</FKey2>
</Path2Child>
<Path2Child>
<FKey1>2</FKey1>
<FKey2>2</FKey2>
</Path2Child>
</Path2Parent>
</ConstraintScope>
</Root>
The first Path2Parent/Path2Child sequence should not validate should it?!?