Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 27th, 2006, 04:15 PM
Miguel Isidoro
Guest
 
Posts: n/a
Default 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
  #2  
Old July 27th, 2006, 07:05 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: xsd:unique - validate attriubte value for whole



Miguel Isidoro wrote:

Quote:
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.
Quote:
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/
  #3  
Old July 28th, 2006, 11:05 AM
Miguel Isidoro
Guest
 
Posts: n/a
Default Re: xsd:unique - validate attriubte value for whole

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:
Quote:
>
>
Miguel Isidoro wrote:
>
>
Quote:
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.
>
Quote:
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/
>
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles