473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Keys and references

I have an element named "vendingMachine". This may appear in one of two
places

<customerSite>
<vendingMachines>

or

<plannedVisit>
<installationTask>
Because of this I made an element named vendingMachine and simply referred
to it when needed <xs:element ref="vendingMachine"/>. Various other parts
of my XML need to refer to a vending machine by its serial number. My
questions are
1) How do I define a key on vendingMachine @serialNumber so that it is
unique within the whole document no matter where it appears
2) How do I define a reference to a vending machine which could be in either
place?

Within <xs:schemaI have the following
<xs:key name="vendingMachineSerialNumberKey">
<xs:selector xpath="vendingMachine"/>
<xs:field xpath="@serialNumber"/>
</xs:key>

and using the key:
<xs:keyref name="visitActionVendingMachineSerialNumber"
refer="vendingMachineSerialNumberKey">
<xs:selector
xpath="roundData/visitDay/plannedVisits/plannedVisit/tasks/*"/>
<xs:field xpath="@vendingMachineSerialNumber"/>
</xs:keyref>

but when I validate my XML in XmlSpy I get the following error:
Identity constraint visitActionVendingMachineSerialNumber did not match
within the scope of element <data>. The referenced identity constraint
"vendingMachineSerialNumberKey" is out of scope

Can anyone help?
Thanks!
Pete
Jul 6 '06 #1
2 1479
1) How do I define a key on vendingMachine @serialNumber so that it is
unique within the whole document no matter where it appears
Place the key definition vendingMachineSerialNumberKey on the root element
of the document. Note the .// in the selector xpath to select all descendant
vendingMachine nodes
<xs:key name="vendingMachineSerialNumberKey">
<xs:selector xpath=".//vendingMachine"/>
<xs:field xpath="@serialNumber"/>
</xs:key>

2. The spec requires that the keyref be defined on an element that is an
ancestor or self of the element on which the key is defined. If you move the
keyref definition to the root element as well, this should work as both the
key and the keyref will be defined on the same element.

Thanks,
Priya

"Peter Morris [Droopy eyes software]" <pe**@droopyeyes.no.com.spamwrote in
message news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have an element named "vendingMachine". This may appear in one of two
places

<customerSite>
<vendingMachines>

or

<plannedVisit>
<installationTask>
Because of this I made an element named vendingMachine and simply referred
to it when needed <xs:element ref="vendingMachine"/>. Various other parts
of my XML need to refer to a vending machine by its serial number. My
questions are
1) How do I define a key on vendingMachine @serialNumber so that it is
unique within the whole document no matter where it appears
2) How do I define a reference to a vending machine which could be in
either place?

Within <xs:schemaI have the following
<xs:key name="vendingMachineSerialNumberKey">
<xs:selector xpath="vendingMachine"/>
<xs:field xpath="@serialNumber"/>
</xs:key>

and using the key:
<xs:keyref name="visitActionVendingMachineSerialNumber"
refer="vendingMachineSerialNumberKey">
<xs:selector
xpath="roundData/visitDay/plannedVisits/plannedVisit/tasks/*"/>
<xs:field xpath="@vendingMachineSerialNumber"/>
</xs:keyref>

but when I validate my XML in XmlSpy I get the following error:
Identity constraint visitActionVendingMachineSerialNumber did not match
within the scope of element <data>. The referenced identity constraint
"vendingMachineSerialNumberKey" is out of scope

Can anyone help?
Thanks!
Pete

Jul 6 '06 #2
You will also have to use apporpriate namespace prefixes with xpath
expressions. Assuming that namespace prefix for vendingMachine element is
myTNS, Priya's example should be

<xs:key name="vendingMachineSerialNumberKey">
<xs:selector xpath=".//myTNS:vendingMachine"/>
<xs:field xpath="@serialNumber"/>
</xs:key>

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Priya Lakshminarayanan" <pr****@microsoft.comwrote in message
news:uP**************@TK2MSFTNGP03.phx.gbl...
1) How do I define a key on vendingMachine @serialNumber so that it is
unique within the whole document no matter where it appears
Place the key definition vendingMachineSerialNumberKey on the root element
of the document. Note the .// in the selector xpath to select all
descendant vendingMachine nodes
<xs:key name="vendingMachineSerialNumberKey">
<xs:selector xpath=".//vendingMachine"/>
<xs:field xpath="@serialNumber"/>
</xs:key>

2. The spec requires that the keyref be defined on an element that is an
ancestor or self of the element on which the key is defined. If you move
the keyref definition to the root element as well, this should work as
both the key and the keyref will be defined on the same element.

Thanks,
Priya

"Peter Morris [Droopy eyes software]" <pe**@droopyeyes.no.com.spamwrote
in message news:%2****************@TK2MSFTNGP05.phx.gbl...
>>I have an element named "vendingMachine". This may appear in one of two
places

<customerSite>
<vendingMachines>

or

<plannedVisit>
<installationTask>
Because of this I made an element named vendingMachine and simply
referred to it when needed <xs:element ref="vendingMachine"/>. Various
other parts of my XML need to refer to a vending machine by its serial
number. My questions are
1) How do I define a key on vendingMachine @serialNumber so that it is
unique within the whole document no matter where it appears
2) How do I define a reference to a vending machine which could be in
either place?

Within <xs:schemaI have the following
<xs:key name="vendingMachineSerialNumberKey">
<xs:selector xpath="vendingMachine"/>
<xs:field xpath="@serialNumber"/>
</xs:key>

and using the key:
<xs:keyref name="visitActionVendingMachineSerialNumber"
refer="vendingMachineSerialNumberKey">
<xs:selector
xpath="roundData/visitDay/plannedVisits/plannedVisit/tasks/*"/>
<xs:field xpath="@vendingMachineSerialNumber"/>
</xs:keyref>

but when I validate my XML in XmlSpy I get the following error:
Identity constraint visitActionVendingMachineSerialNumber did not match
within the scope of element <data>. The referenced identity constraint
"vendingMachineSerialNumberKey" is out of scope

Can anyone help?
Thanks!
Pete


Jul 6 '06 #3

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

Similar topics

31
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...
26
by: pb648174 | last post by:
I have a table called BidItem which has another table called BidAddendum related to it by foreign key. I have another table called BidFolder which is related to both BidItem and BidAddendum, based...
10
by: D. Dante Lorenso | last post by:
I'd like to run a clean up command on my tables to eliminate rows that I'm no longer using in the database. I want to do something like this: DELETE FROM tablename WHERE...
6
by: Andreas | last post by:
Hello list, what about uniqueness of inherited primary keys ? eg you have : create table objects ( id int4, date_created timestamp(0), primary key (id)
9
by: Miky | last post by:
Hi, I need to send Ctrl-PgUp (or Ctrl-PgDown) to the active application but when I use SendKeys.Send("^{PGUP}"), the program understands it as just PageUp. How may I solve it? Thanks in...
1
by: Thomas T. Thai | last post by:
I'm looking for a better way to make use of foreign keys. Here is a sample setup: -- TESTING Foreign Keys create table mod ( mod_id int not null primary key, name varchar(32) not null...
90
by: Christoph Zwerschke | last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist only since Python 2.4. Anyway, I was thinking about whether it would be possible and desirable to change the old behavior in...
2
by: jphelan | last post by:
I was testing the install and uninstall, on my WindowsXP Pro SP2 machine, of software that I created, called, "inbusiness". Because of the following error message that I received on attempting to...
11
by: garyhoran | last post by:
Hi Guys, I have a collection that contains various attributes (stuff like strings, DateTime and Timespan) . I would like to access the collection in various orders at different points in the...
4
by: Peter | last post by:
I am interested in informed feedback on the use of Constraints, Primary Keys and Unique. The following SQL statement creates a Bands tables for a database of bookings Bands into Venues, where the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.