This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes How to make an element value unique within entire instance document? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to make an element value unique within entire instance document?" Watch "How to make an element value unique within entire instance document?" New topic
Author

How to make an element value unique within entire instance document?

Robert Dang
Greenhorn

Joined: Jul 20, 2004
Posts: 3
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, as I don't have much knowledge of xpath.

here is my 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:


But this one would be valid:

[ July 26, 2004: Message edited by: Robert Dang ]
[ July 26, 2004: Message edited by: Robert Dang ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to make an element value unique within entire instance document?