473,569 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems with key/keyref and complex-type inheritance

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=AExte nded".

I want to have type safety for the reference "Ref_to_AExtend ed" 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_AExtend ed" element of type
"B".

But there's a problem: The XPath expressions in key/keyref do not
allow to contain tests like [@type="AExtende d"]. 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:complexTy pe name="Root">
<xs:sequence>
<xs:element name="A" type="ABase"
minOccurs="0"
maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="ABase">
<xs:attribute name="key" type="xs:ID" use="required"/
>
</xs:complexType>
<xs:complexTy pe name="AExtended ">
<xs:complexCont ent>
<xs:extension base="ABase"/>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="B">
<xs:sequence>
<xs:element name="Ref_to_AE xtended"
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:noNamespace SchemaLocation= "test.xsd">
<A xsi:type="AExte nded" key="key1"/>
<B>
<Ref_to_AExtend ed>key1</Ref_to_AExtende d>
</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="InvalidKe y">
<xs:selector xpath="A[@type="AExtende d"]"/>
<xs:field xpath="@key"/>
</xs:key>
<xs:keyref name="InvalidKe yref" refer="InvalidK ey">
<xs:selector xpath="B/Ref_to_AExtende d"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>

Feb 12 '07 #1
0 1628

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

Similar topics

0
1213
by: mark.van.der.voort | last post by:
Hi, I have defined a simple key/keyref validation for describing a tree. <xs:key name="key_member"> <xs:selector xpath=".//member"/> <xs:field xpath="@id"/> </xs:key> <xs:keyref name="ref_parent_member" refer="key_member"> <xs:selector xpath=".//member"/>
2
2002
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 to xml schema. The structure is as follows: Request Report
3
1288
by: Mike | last post by:
In my XML document, I am defining a key on an element, which works fine. I also have the corresponding keyref element in place to enforce ref. integrity. The issue: it's not necessary that an entity have a parent. But, if a parent ID is specified I want to validate that against the key. For example: <Objects> <Object> <ID>1</ID>
2
1643
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 preferredMovieId="3"> </movie> <movie id="2"> <actor preferredMovieId="2">
6
1801
by: Roland Praehofer | last post by:
Hi! I'm trying to accomplish the following: <root xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='teaser.xsd'> <b> <a>John</a> <a>Paul/a>
4
1645
by: jasonnerothin | last post by:
I'm trying to figure out exactly what's going wrong with an xpath keyref validation scenario. In brief, I have something like the following in my xsd: <xs:schema> <xs:complexType name="topLevelContainer"> <!-- define an element --> <xs:complexType name="element"> ...
0
1178
by: mavis | last post by:
Does IntellJ support the checking for "keyref" definition? Why it seems does not work at all? <xs:key name="supported-platforms-name-unique"> <xs:selector xpath=".//supported-platforms/platform"/> <xs:field xpath="."/> </xs:key> <xs:keyref name="platforms-name-ref"
0
1368
by: Gerry Laenen | last post by:
Hi all, I am currently working on creating an XSD schema. I have an element defined that should be self-refering (child-parent principle). Here is a sample: <GWLC> <GROUPS> <GROUP> <NAME>ParentGroup</NAME> <PARENT></PARENT>
0
1526
by: =?Utf-8?B?cm9zYW5h?= | last post by:
I have a xsd, schema get about a Microsoft tool using my own Database. I need modify in code the structure Keyref element, but don't add a standard item. I need add my own Attributes.(Attribute1,Attribute2...) I look for an example to use xmlschemakeyref UnhandledAttributes. Example: <xs:keyref name="OutputKey" atributo1=" "...
0
1774
by: Ridius | last post by:
Hello. I start to study XML and have a question. What`s the difference between ID/IDREF and Key/Keyref? What's better to use? Thanks.
0
7614
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.