You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Olivier CHAPITEAU <oc...@arkoon.net> on 2006/01/13 10:01:53 UTC

key, keyref with namespace : not working

If i declare a target namespace in a schema using key and keyref, 
constraint isn't verified by validate (alwasy tell valid)
did i do a mistake in my schemas or is it a bug ?

thanks,

the details of schema and sample xml :

The keyref.xsd with a target namespace declared :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="test" xmlns="test"
    elementFormDefault="qualified">
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="List" type="ListType"/>
                <xs:element name="Refs" type="RefType"/>
            </xs:sequence>
        </xs:complexType>
        <xs:key name="myId">
            <xs:selector xpath=".//List/a"/>
            <xs:field xpath="./@id"/>
        </xs:key>
        <xs:keyref refer="myId" name="myIdRef">
            <xs:selector xpath=".//Refs/b"/>
            <xs:field xpath="./@idref"/>
        </xs:keyref>
    </xs:element>
    <xs:complexType name="ListType">
        <xs:sequence>
            <xs:element name="a" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="id" type="xs:NCName" 
use="required"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="RefType">
        <xs:sequence>
            <xs:element name="b" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="idref" type="xs:NCName" 
use="required"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

here's a nonvalid.xml document :

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="test" >
    <List>
        <a id="x"/>
      <a id="y"/>
    </List>
    <Refs>
        <b idref="x"/>
        <b idref="y"/>
        <b idref="z"/>
    </Refs>
</root>

if I do  "validate keyref.xsd nonvalid.xml" , it tell me that document is 
valid.

Removing any  targetnamespace declaration, the key is correctly checked :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="test" xmlns="test"
    elementFormDefault="qualified"> become <xs:schema 
xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <root xmlns="test" > become <root> in xml doc


then, the validation fail :"key ref "z" not found", as awaited

Olivier,