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

xsd:unique - validate attriubte value for whole

Hi all,

I am trying to include a xsd:unique element in my schema to make an
attribute of an element unique at the whole document level.

Consider the following xml fragment:

<Form>
<Question>
<Response id="response1">
</Response>
<Response id="response1">
</Response>
</Question>
<Question>
<Response id="response1">
</Response>
</Question>
</Form>

Here is a fragment of my schema:

<xs:complexType name="Question">
<xs:sequence>
<xs:element minOccurs="0" name="Response" type="Response">
</xs:element>
<xs:unique name="questionResponseNameUnique">
<xs:selector xpath="Response" />
<xs:field xpath="@id" />
</xs:unique>

The problem with my schema is that it only validates the duplicate id
<Responseelements inside the same <Questionelement, not at the whole
document level as I want. Is there any way to achieve this?

Thanks
Miguel
Jul 27 '06 #1
2 1990


Miguel Isidoro wrote:

I am trying to include a xsd:unique element in my schema to make an
attribute of an element unique at the whole document level.
The problem with my schema is that it only validates the duplicate id
<Responseelements inside the same <Questionelement, not at the whole
document level as I want. Is there any way to achieve this?
Why don't you simply type that attribute as type xs:ID?

If you want to use the xs:unique element then you need to put it in the
definition of the root element (e.g. the Form element).
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 27 '06 #2
Problem solved. Thanks for the tip. I had already tried that but with the
wrong syntax. Here is the example I have:

<xs:key name="responseNameKey">
<xs:selector xpath="./QuestionList/Question/ResponseList/Response |
../QuestionList/Question/ResponseList/Response/ResponseOptions/ResponseOption
|
../QuestionList/Question/QuestionGroupList/QuestionGroup/ResponseList/Response
|
../QuestionList/Question/QuestionGroupList/QuestionGroup/ResponseList/Response/ResponseOptions/ResponseOption
|
../QuestionList/Question/QuestionGroupList/QuestionGroup/QuestionList/Question/ResponseList/Response
|
../QuestionList/Question/QuestionGroupList/QuestionGroup/QuestionList/Question/ResponseList/Response/ResponseOptions/ResponseOption" />
<xs:field xpath="@name" />
</xs:key>

It is this complicated because not all elements have an attribute that
should be considered an unique key, so I enumerated the elements that have
the attribute that can't be repeated. I included this schema fragment at the
root level.

Tnanks a lot
Miguel
"Martin Honnen" wrote:
>

Miguel Isidoro wrote:

I am trying to include a xsd:unique element in my schema to make an
attribute of an element unique at the whole document level.
The problem with my schema is that it only validates the duplicate id
<Responseelements inside the same <Questionelement, not at the whole
document level as I want. Is there any way to achieve this?

Why don't you simply type that attribute as type xs:ID?

If you want to use the xs:unique element then you need to put it in the
definition of the root element (e.g. the Form element).
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 28 '06 #3

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

Similar topics

2
by: Sebastian Kerekes | last post by:
Greetings, I'm new to XSD and I'm trying to create a schema for the following: The document 'persons' should contain 0+ elements of type 'person', which has a subelement called 'name' which is a...
0
by: Stone | last post by:
Dear all If I have the following xml file : <myxml> <body> <text>My text</text> <num_attach>2</num_attach> </body> <file id="1">
0
by: Giuseppe | last post by:
Hello, Here's a sample of a file.xsd and file.xml I wrote : File.xsd: <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="LogErrori" targetNamespace="http://tempuri.org/LogErrori.xsd"...
3
by: Mike P | last post by:
I have an xml doucument that I want to validate with a XSD schema. I'm new to this and I don't know exactly how I make the references at the top of the documents so that the XSD file will validate...
1
by: John Smith | last post by:
Ok, I have 2 xml files that are really similar. They have the exact same structure exept that in one XML some element are required and in the other they are simply absent from the xml. Problem...
3
by: Lynn | last post by:
Hi all, I am having problem when did the validation of XML document with Schema. my schema is like the following: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="schema.xsd"...
1
by: Jim Di Griz | last post by:
Hi I have a problem to create an XSD that prevents overlapping ranges. Sample XML: <root> <element LowerLimit="1" UpperLimit="50000"> ..... </element>
2
by: Bardo | last post by:
Hi all, Does anyone know if it is possible, and if so how, to perform validation of a simple non XML string against certain XSD restrictions, without having the entire XML document to validate...
1
by: reachkaruna | last post by:
Hi All, I have the following XSD where my "number" is having unique constarint <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.