problems with key/keyref and complex-type inheritance

peterpeter

Usenet Archive
Joined
Feb 11, 2004
Messages
4
Reaction score
0
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 xmlns:xs="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> <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 xmlns:xsi="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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top