473,661 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Schema keys, uniqueness based on ancestor's attribute

Is the following constraint possible to be expressed with XML Schema
(and how):

Suppose we have a document in the form

<car type="ford">
<part name="door"/>
<part name="ashtray"/>
</car>

<car type="bmw">
<part name="door"/>
....
</car>

Is it possible to define a key for the parts of a car such that the key
will include the type of the car too.

In this way the door of the BMW will be unique because a) it's a door
and b) it is part of the BMW and will differ from the door of the Ford
since it is not defined in the ford.
Say the schema is

<xs:schema>
<xs:element name="car">
<xs:complexType >
<xs:sequence>
<xs:element name="part" maxOccurs="unbo unded">
<xs:complexType >
<xs:complexCont ent>
<xs:attribute name="name" type="xs:string "/>
</xs:complexConte nt>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

So i want a key definition that uniquely identifies the element "part"
of the element "car" by using the part's "name" attribute *and* the
car's "name" attribute.

I thought something in the line of

<xs:key name="partKey">
<xs:selector xpath="car/part"/>
<xs:field xpath="@name"/>
<xs:field xpath="../@name"/>
</xs:key>

BUT, the XML Schema recommendation' s restricted XPATH usage in key
definitions forbids that.

Any other ideas?

O.
Jul 20 '05 #1
0 1559

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

Similar topics

31
3367
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific customer subtypes: 1 - business, 2 - home, 3 - university
2
4655
by: Olaf Meyer | last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints specified in the schema (e.g. constraints specified via unique element). The validation works with the XML editor I'm using (XMLSpy4) but not with Xerces 2.6.0. I've included a really short and simple example to illustrate it. I would like to get some comments on the validation capabilities of Xerces 2.6.0. I though it *fully* supported W3C Schema!
0
1623
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 precise here a short and simple XML document. The "objects" have a key constraint on the id attribute, i.e. they need to be unique. The object-ref element may reference the previously defined objects and hence has a keyref constraint on the id attribute. I would now like to furhter restrict the...
1
1418
by: Maxim | last post by:
If there is a document like this: <Configurations> <Configuration default="true"> ... </Configuration> <Configuration> ...
2
2486
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the target namespace of the components from the included schema document. I'm confused because of the rules I read in the XML Schema spec <http://www.w3.org/TR/xmlschema-1/#element-element>: > If the <element> element information item has <schema>...
6
2579
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
1
1562
by: Mr. Almenares | last post by:
Hello: I’m trying to do a schema with recurrent structure for a Book like a Node can have many Nodes inside or One leave. So, the leaves have an attribute that is Identifier. My goal is define Uniqueness that guarantees to the attribute Identifier his uniqueness. That I don’t know the depth of levels I have to put in the xpath attribute of the selector something like this TOC/descendant::Tree/Data, but this is not allow. How I can...
13
1905
by: Martin Z | last post by:
I'm making a CRUD screen for an Oracle database... but problem is that the primary key in that table is populated via an autonumber, which in Oracle is done just with triggers and sequences. Suffice to say that ADO.Net 1.1 is unaware that this column is, despite appearances, optional - which is a problem when creating new rows. I was wondering what the best way to remove the constraint is? I've been bitten too many times by assuming the...
0
2811
by: icesign | last post by:
I know that the selector of these elements has a scope relative to the element being declared, but maybe there is a way to get beyond bounds of this scope or maybe just a way to extend base element? Here’s a working example: <xs:schema id="schema" targetNamespace="http://tempuri.org/schema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/schema.xsd" xmlns:mstns="http://tempuri.org/schema.xsd" ...
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.