473,320 Members | 1,862 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,320 software developers and data experts.

help with xml schema -- making a unique key

Hi, please take a look at this schema and tell me how I can make the
value of my AttachmentKey element(s) unique within the entire instance
document.

I know that I have to use <key> or <unique>, but I can't get it to
work. I don't have knowledge of xpath and the examples I find on the
web aren't working.

here is my schema:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="test.ns.abc">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:A"/>
<xsd:element ref="ns:Attachment" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Attachment">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:AttachmentKey"/>
<xsd:element ref="ns:AttachmentName"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AttachmentText" type="xsd:string"/>
<xsd:element name="AttachmentName" type="xsd:string"/>
<xsd:element name="AttachmentPageTotal" type="xsd:int"/>
<xsd:element name="A">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:B"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="B">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ns:Attachment"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AttachmentKey"/>
</xsd:schema>

--------------

As you can see, AttachmentKey is a subelement of Attachment, and is
used in more than one place in the example above. I want it so that
when the instance document is created, no matter how many instances of
Attachment is in it, each AttachmentKey value is unique, so that I can
use them as keys.

So this following instance doc would be invalid:

<root>
<A>
<B>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</B>
</A>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
<Attachment>
<AttachmentKey>2</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</root>

But this one would be valid:

<root>
<A>
<B>
<Attachment>
<AttachmentKey>1</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</B>
</A>
<Attachment>
<AttachmentKey>2</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
<Attachment>
<AttachmentKey>3</AttachmentKey>
<AttachmentName>Name</AttachmentName>
</Attachment>
</root>

thanks!
Jul 20 '05 #1
1 2718
Hi,

Within your declaration of root (before the </xs:element>), you should
add

<xsd:key name="uniqueAttachment">
<xsd:selector xpath=".//ns:Attachment"/>
<xsd:field xpath="ns:AttachmentKey"/>
</xsd:key>

You also need to give AttachmentKey a simple type (or a complex type
with simple content).

Hope that helps,
Priscilla

-----------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (Prentice Hall PTR)
http://www.datypic.com
-----------------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2

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

Similar topics

1
by: Gianni Rubagotti | last post by:
I'm writing an XMl schema to learn and I have a problem I want that my schema work on my PC, not to put it on the internet but everytime I serach in tutorials the examples put as value of...
2
by: Anita C | last post by:
Hi, How do I associate or map a specific column in a datatable to a particular element present in an xml document - to read into a datatable as well as write from the datatable to the xml element?...
0
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
6
by: LesleyW | last post by:
Hi Apologies if this is a really dumb question, but being new to XML and Schemas, I wonder if giving the namespace for eg xsd or xsi as a website address means that the user has to be online...
2
by: smachin1000 | last post by:
Hi All, In the sample schema & document below, I'd like the attribute "name" to be unique for all function elements under function_list. The tools I'm using (XML Spy and xmllint) all validate...
1
by: daldridge | last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't yet been able to get appropriate template/select/for-each processing working. I don't fully grok the Muenchian technique yet...
0
by: pr | last post by:
I have the following sample XML File: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <parent> <child ref="1"><grandchild>tom</grandchild></child> <child...
1
by: tthunder | last post by:
Hi @all, Please check the following XML file and XML schema definition below first: ------- XML File (full): ------- <?xml version="1.0" encoding="UTF-8"?>
0
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?...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.