Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

problems with key/keyref and complex-type inheritance

 
 
peterpeter
Guest
Posts: n/a
 
      02-12-2007
Hi.

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
"B".

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...

PETER

Here is the schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root" type="Root"/>
<xs:complexType name="Root">
<xs:sequence>
<xs:element name="A" type="ABase"
minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ABase">
<xs:attribute name="key" type="xs:ID" use="required"/
>

</xs:complexType>
<xs:complexType name="AExtended">
<xs:complexContent>
<xs:extension base="ABase"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="B">
<xs:sequence>
<xs:element name="Ref_to_AExtended"
type="xs:IDREF"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

And here is an instance example:

<?xml version="1.0" encoding="UTF-8"?>
<Root xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<A xsi:type="AExtended" key="key1"/>
<B>
<Ref_to_AExtended>key1</Ref_to_AExtended>
</B>
</Root>

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:key>
<xs:keyref name="InvalidKeyref" refer="InvalidKey">
<xs:selector xpath="B/Ref_to_AExtended"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>

 
Reply With Quote
 
 
 
Reply

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



Advertisments