Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2006

Tip: Looking for answers? Try searching our database.

xsd:unique - validate attriubte value for whole

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Miguel Isidoro - 27 Jul 2006 16:19 GMT
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
<Response> elements inside the same <Question> element, not at the whole
document level as I want. Is there any way to achieve this?

Thanks
Miguel
Martin Honnen - 27 Jul 2006 19:06 GMT
> 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
> <Response> elements inside the same <Question> element, 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).

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Miguel Isidoro - 28 Jul 2006 11:06 GMT
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

> > 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.
[quoted text clipped - 7 lines]
> 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).

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.