• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSD: unique attribute values?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ben Verbeken
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic