469,133 Members | 1,153 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

XML schema - key/keyref and inheritance


There is a XML schema problem that I have with key/keyref:

I have two complex (A and B) types which both inherit from a common
base typ (Base). A refers B using a xs:IDREF element named Ref_to_A.
Both are allowed to be instantiated under the root element by
declaring an element of the base class.

I want to have type safety for the reference by using key/keyref.
There should be a key definition for the @key attribute of type A and
a keyref definition between this key and the Ref_to_A element of type

But there's a problem: The XPath expressions in key/keyref do not
allow to contain tests like [@type='A']. How can I reach the instance
element of type A or B with my XPAth? Or is there another solution?

Thanks for helpful answers...

Here is the schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root" type="Root"/>
<xs:complexType name="Root">
<xs:element name="Base" type="Base" minOccurs="0"
<xs:complexType name="Base" abstract="true">
<xs:attribute name="key" type="xs:ID" use="required"/>
<xs:complexType name="A">
<xs:extension base="Base"/>
<xs:complexType name="B">
<xs:extension base="Base">
<xs:element name="Ref_to_A" type="xs:IDREF"/>

And here is an instance example:

<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<Base xsi:type="A" key="key1"/>
<Base xsi:type="B" key="key2">

I planned these key/keyref to be within my instance element
declaration of the Root:

<xs:element name="Root" type="Root">
<xs:key name="InvalidKey">
<xs:selector xpath="Base[@type="A"]"/>
<xs:field xpath="@key"/>
<xs:keyref name="InvalidKeyref" refer="InvalidKey">
<xs:selector xpath="Base[@type="B"]/Ref_to_A"/>
<xs:field xpath="."/>
Jul 20 '05 #1
0 3060

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Olaf Meyer | last post: by
5 posts views Thread by Harald Haspl | last post: by
2 posts views Thread by John Carron | last post: by
2 posts views Thread by svestin | last post: by
2 posts views Thread by bmichel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.