← Prev in month ← Prev in thread

schema keyref to other schema.

From
Stephan Dick <>
To
Date
2005-02-22T10:45:30Z
ID
<>
Thread
schema keyref to other schema.
Hi

I defined two schemas somewhat like a RDB model. One holds a primary key 
and the other one a foreign key pointing to the primary key. Now the 
schemas are valid (in Stylus Studio XML) but i can't get the xml file to 
validate. How can i tell the "slave"-xml file to include the "master" 
file? Any help is really appreciated!

key.xsd
-------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:test="http://www.test.com/test" 
targetNamespace="http://www.test.com/test" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="primary" type="xs:string">
                    <xs:key name="PrimaryKey">
                        <xs:selector xpath="./primary"/>
                        <xs:field xpath="."/>
                    </xs:key>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

foreignKey.xsd
--------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:test="http://www.test.com/test" elementFormDefault="qualified" 
attributeFormDefault="unqualified">
    <xs:import namespace="http://www.test.com/test" 
schemaLocation="Key.xsd"/>
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="foreignKey" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
        <xs:keyref name="ForeignKeyRef" refer="test:PrimaryKey">
            <xs:selector xpath="./foreignKey"/>
            <xs:field xpath="."/>
        </xs:keyref>
    </xs:element>
</xs:schema>

TestKey.xml -> valid!
------------
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.test.com/test"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.test.com/test D:\Temp\FK\Key.xsd">

    <primary>Primary</primary>
</root>

TestForeignKey.xml Error: The keyref 'ForeignKeyRef' refers to a 
key/unique that is out of scope.
------------------
<?xml version="1.0" encoding="UTF-8"?>
<root     xmlns:test="http://www.test.com/test"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="D:\Temp\FK\ForeignKey.xsd">
    <foreignKey>Primary</foreignKey>
</root>
← Prev in month ← Prev in thread