W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2002

Problems with keys and keyrefs

From: Gabriele Zannoni <gzannoni@supereva.it>
Date: Sat, 2 Mar 2002 07:39:49 -0500 (EST)
Message-ID: <002901c1c1e7$839f8400$8119fea9@gabriele>
To: <xmlschema-dev@w3.org>
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 10:29:53 GMT

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