472,333 Members | 1,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

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 3178

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Olaf Meyer | last post by:
I'm wondering if I can also express uniquness constraints on attributes of objects that I have referenced from somewhere else. To be a bit more...
by: Victor | last post by:
I have a Schema with some elements which are "types" or objects, and some elements which correspond to instances of the types. How can I specify...
by: Rabe | last post by:
Hi all, here a little brain-twister (starting to spoil my weekend if I do not find a solution ... ;-) ) What I want to do is to find a...
by: Harald Haspl | last post by:
Hello, I've appended a simple XML file and it's appropriate schema below. I want to validate the XML file against the schema with xerces-c. ...
by: John Carron | last post by:
Hi All, I have written a simple schema (see below) that uses substitution groups. I don't know if this the correct usage because I'm fairly new...
by: Jaunedeau | last post by:
I have some XML that must look like this : <movies> <movie id="1"> <actor preferredMovieId="1"> <actor preferredMovieId="2"> <actor...
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1"...
by: svestin | last post by:
Hi All! I run into a problem defining a XSD schema with KEYREF references. Is it possible to use KEYREF with nillable fields? Just like a...
by: bmichel | last post by:
Regarding the XSD schema shown below, I want to modifiy it so that: - the "owner_id" attribute in the "dog" element to exist in one of the "owner"...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.