Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > problems with key/keyref and complex-type inheritance

Thread Tools

problems with key/keyref and complex-type inheritance

Posts: n/a

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

I have a complex type "AExtended" which inherits from a base type
"ABase". Both are allowed to be instantiated under the "Root" element
by declaring an element of the base class with name "A" and either
"xsi:type=ABase" or "xsi:type=AExtended".

I want to have type safety for the reference "Ref_to_AExtended" from
another type/element "B" by using key/keyref. A reference to an
instance of type "ABase" is not allowed. So, there should be a key
definition for the @key attribute of type "AExtended" and a keyref
definition between this key and the "Ref_to_AExtended" element of type

But there's a problem: The XPath expressions in key/keyref do not
allow to contain tests like [@type="AExtended"]. How can I reach the
instance element of type "AExtended" 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 xmlnss="">
<xs:element name="Root" type="Root"/>
<xs:complexType name="Root">
<xs:element name="A" type="ABase"
<xs:complexType name="ABase">
<xs:attribute name="key" type="xs:ID" use="required"/

<xs:complexType name="AExtended">
<xs:extension base="ABase"/>
<xs:complexType name="B">
<xs:element name="Ref_to_AExtended"

And here is an instance example:

<?xml version="1.0" encoding="UTF-8"?>
<Root xmlnssi=""
<A xsi:type="AExtended" key="key1"/>

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="A[@type="AExtended"]"/>
<xs:field xpath="@key"/>
<xs:keyref name="InvalidKeyref" refer="InvalidKey">
<xs:selector xpath="B/Ref_to_AExtended"/>
<xs:field xpath="."/>

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
inheritance, multiple inheritance and the weaklist and instance dictionaries Rouslan Korneychuk Python 8 02-10-2011 04:02 AM
Interface inheritance vs Implementation inheritance. Daniel Pitts Java 27 02-27-2008 01:37 AM
Private Inheritance and Publice Inheritance karthikbalaguru C++ 9 09-10-2007 01:05 PM
mul. inheritance & overloading operator new/delete solved by virtual base inheritance? cppsks C++ 0 10-27-2004 07:49 PM
Private access modifier and Inheritance (Inheritance implementation in Java) maxw_cc Java 1 12-21-2003 11:38 AM