W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2004

RE: Question about <unique/>/<keyref/>

From: Michael Kay <mhk@mhk.me.uk>
Date: Sat, 17 Jan 2004 11:20:02 -0000
To: <john.madden@duke.edu>, <xmlschema-dev@w3.org>
Message-ID: <006201c3dceb$da2b1e30$6401a8c0@pcukmka>
My reading is that Clause 4.3 of section 3.11.4 places constraints on
nodes in the "qualified node set" of a keyref, which is defined as "the
subset of the  <http://www.w3.org/TR/xmlschema-1/#key-tns> .target node
set. for which all the  <http://www.w3.org/TR/xmlschema-1/#fields>
{fields} evaluate to a node-set with exactly one member ". It doesn't
place any constraints on members of the target node-set that aren't in
the qualified node-set, that is, nodes for which one or more of the
fields are "null".
 
Presumably someone thought that SQL does it this way and therefore it
makes sense.
 
Michael Kay

-----Original Message-----
From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org]
On Behalf Of John F. Madden
Sent: 17 January 2004 00:13
To: xmlschema-dev@w3.org
Subject: Question about <unique/>/<keyref/>


Hi,
 
A construct involving a <unique/>/<keyref/> pair is not giving me the
validation behavior that I anticipate.
 
As I read the schema specification, the instance below should NOT
validate against the schema below. However, with the validator that I am
using, the instance DOES validate. 
 
Who's right here: me or the machine?
 
John
======================

John F. Madden
Duke University Medical Center
 
<!--Am I right to think the following instance should be INVALID...?-->

<Root xmlns="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="test.xsd">

     <KeyElement KeyField1="1" KeyField2="a"/>

     <KeyElement KeyField1="2" KeyField2="b"/>

     <KeyElement KeyField1="3"/>

     <KeyElement KeyField2="c"/>

     <KeyrefElement KeyrefField1="1" KeyrefField2="a"/>

     <KeyrefElement KeyrefField1="2" KeyrefField2="b"/>

     <KeyrefElement KeyrefField1="3"/>

     <KeyrefElement KeyrefField2="c"/>

     <KeyrefElement KeyrefField1="ThisKeyValueDoesNotExist"/>

     <KeyrefElement KeyrefField2="NeitherDoesThisOne"/>

</Root>

 

 

<!--...if this is the schema I'm validating against...-->

<xs:schema targetNamespace="test" xmlns="test"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

     <xs:element name="Root">

          <xs:complexType>

               <xs:choice maxOccurs="unbounded">

                         <xs:element name="KeyElement"
type="KeyElementType" maxOccurs="unbounded"/>

                         <xs:element name="KeyrefElement"
type="KeyrefElementType" maxOccurs="unbounded"/>

               </xs:choice>

          </xs:complexType>

          <xs:unique name="Uniqueness">

               <xs:selector xpath=".//KeyElement"/>

               <xs:field xpath="@KeyField1"/>

               <xs:field xpath="@KeyField2"/>

          </xs:unique>

          <xs:keyref name="ReferentialIntegrity" refer="Uniqueness">

               <xs:selector xpath=".//KeyrefElement"/>

               <xs:field xpath="@KeyrefField1"/>

               <xs:field xpath="@KeyrefField2"/>

          </xs:keyref>

     </xs:element>

     <xs:complexType name="KeyElementType">

          <xs:complexContent>

               <xs:extension base="xs:anyType">

                    <xs:attribute name="KeyField1" type="xs:string"/>

                    <xs:attribute name="KeyField2" type="xs:string"/>

               </xs:extension>

          </xs:complexContent>

     </xs:complexType>

     <xs:complexType name="KeyrefElementType">

          <xs:complexContent>

               <xs:extension base="xs:anyType">

                    <xs:attribute name="KeyrefField1" type="xs:string"/>

                    <xs:attribute name="KeyrefField2" type="xs:string"/>

               </xs:extension>

          </xs:complexContent>

     </xs:complexType>

</xs:schema>

This email was sent on 1/16/04 at 7:13 PM.
Received on Saturday, 17 January 2004 07:13:57 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:41 GMT