aspose file tools*
The moose likes XML and Related Technologies and the fly likes XSD: unique attribute values? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSD: unique attribute values? " Watch "XSD: unique attribute values? " New topic
Author

XSD: unique attribute values?

Ben Verbeken
Greenhorn

Joined: Jul 14, 2005
Posts: 4
Hi all,

I'm having some trouble with a schema I'm working on. What I want to do is this:

<element name="e1"/>
<element name="e2"/>

I want to make sure that each name attribute is unique. In other words, that this is illegal:

<element name="e1"/>
<element name="e1"/>

Can I define this in an XSD, and if so: how?

Thanks a lot,
Ben
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Maybe I am not clear on what the end use of this Schema is. If you could clarify please.

1. Do you want to restrinct the name to be unique in the Schema or in the XML instance of that adhers to this Schema ie; the element tag 'e1' must appear only ONCE in the XML file.
2. Is 'e1' defined as a global element ?

You can read the XMLSchema specification here.
BTW, sorry about the very delayed response.

- m


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Ben Verbeken
Greenhorn

Joined: Jul 14, 2005
Posts: 4

1. Do you want to restrinct the name to be unique in the Schema or in the XML instance of that adhers to this Schema ie; the element tag 'e1' must appear only ONCE in the XML file.


The instance. I admit my example was very badly chosen, so I'll rephrase

What I want is an xsd construct so that that the following (piece of) an XML document is valid:


and so that this is invalid:


So basically, I want the XSD to be able to put constraints (in casu: uniqueness) on attribute values over different tags.

Thanks a lot for replying, I really would love to find a solution for this one

Cheers,
Ben
[ July 31, 2006: Message edited by: Ben Verbeken ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
One construct which gaurentees uniqueness of "attribute value" (rather than the attribute name) is the 'ID'. So, one solution is that you define the attribute 'bar' of the 'foo' element to be like ID (or is it IDREF ?). Please look up the XSD documentation on how to define it. I don't have the documentation handy and my internet is very flaky today.
Thanks.

- m
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSD: unique attribute values?
 
Similar Threads
problem in applying unique constraint on xml attribute through xsd unique
Validating XML using XSD and with Oracle's DOMParser and XSDBuilder
For all SCWCD guys : Doubts
Cache Configuration problem
create a checklistbox using tld in jsp