- From: Priscilla Walmsley <priscilla@walmsley.com>
- Date: Sat, 2 Mar 2002 11:13:53 -0500
- To: "'Gabriele Zannoni'" <gzannoni@supereva.it>, <xmlschema-dev@w3.org>
Hi Gabriele, There is a requirement that the element declaration in which the key is defined must be a child of (or the same as) the element declaration in which the keyref is defined [1]. So, as you've already noticed, moving the key and keyref definitions up to the document element declaration solves your problem. You could also just move the keyref up to the document element declaration and leave the key where it is. Hope that helps, Priscilla [1] http://www.w3.org/TR/xmlschema-1/#cvc-identity-constraint ------------------------------------------------------------------ Priscilla Walmsley priscilla@walmsley.com Vitria Technology http://www.vitria.com Author, Definitive XML Schema (Prentice Hall PTR) ------------------------------------------------------------------ > -----Original Message----- > From: xmlschema-dev-request@w3.org > [mailto:xmlschema-dev-request@w3.org]On Behalf Of Gabriele Zannoni > Sent: Saturday, March 02, 2002 7:40 AM > To: xmlschema-dev@w3.org > Subject: Problems with keys and keyrefs > > > Hi, > I'm experiencing schemas for a few days and I have some problems > understanding the behavior of keys and keyrefs. > > For example the schema: > <schema targetNamespace="http://tempuri.org/XMLSchema.xsd" > elementFormDefault="qualified" > xmlns:ns="http://tempuri.org/XMLSchema.xsd" > xmlns="http://www.w3.org/2001/XMLSchema"> > <element name="document"> > <complexType> > <sequence> > <element name="keyList" type="ns:keyListType"> > <key name="aKey"> > <selector xpath="ns:key" /> > <field xpath="." /> > </key> > </element> > <element name="keyRefList" type="ns:keyListType"> > <keyref name="aKeyRef" refer="ns:aKey"> > <selector xpath="ns:key" /> > <field xpath="." /> > </keyref> > </element> > </sequence> > </complexType> > </element> > <complexType name="keyListType"> > <sequence> > <element name="key" type="string" maxOccurs="unbounded" /> > </sequence> > </complexType> > </schema> > > runned over the XML: > > <document xmlns="http://tempuri.org/XMLSchema.xsd"> > <keyList> > <key>id1</key> > <key>id2</key> > <key>id3</key> > </keyList> > <keyRefList> > <key>id1</key> > <key>id1</key> > </keyRefList> > </document> > > rises an error: The keyref '{http://tempuri.org/XMLSchema.xsd}aKey' does not resolve to a key for the Identity Constraint '{http://tempuri.org/XMLSchema.xsd}aKeyRef'. The problem disappear if I declare the keys on the "document" element scope. I hope there's someone who can help me. Cheers, Gabriele
Received on Saturday, 2 March 2002 11:12:04 UTC