W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2002

Re: uniqueness question

From: Rahul Srivastava <Rahul.Srivastava@Sun.COM>
Date: Sun, 21 Apr 2002 11:35:02 +0000 (Asia/Calcutta)
Message-Id: <200204210612.g3L6CqF26291@blr-root.India.Sun.COM>
To: xmlschema-dev@w3.org
Cc: jhallett@mail.colgate.edu

Hi Joe,

> Joe Hallett wrote...
> I am trying to specify that the contents of my "UniqueID" element is unqiue
> for every occurance of the element.
> My problem is that the instance doc validates against the schema no matter
> what the contents of "UniqueID" are. When I enter identitcal values for each
> element, such as <UniqueID>a</UniqueID> and <UniqueID>a</UniqueID>, the
> instance doc is validated.  Obviously, I dont want this to happen.
> Here is a portion of my schema:
> <element name="Facts" type="fac:FactsType"/>
>  <complexType name="FactsType">
>   <sequence>
>    <element name="Fact" type="fac:FactType" maxOccurs="unbounded">
>     <unique name="factID">
>      <selector xpath="Fact"/>
>      <field xpath="UniqueID"/>
>     </unique>
>    </element>
>   </sequence>
>  </complexType>

That's a problem!. The unique is declared in element 'Fact' and the xpath for 
selector is also 'Fact'. So, the set of elements selected by selector is a 
single node 'Fact'. Hence the uniqueness is not enforced.

But then, is my schema not valid or why do I not get any error??, you may think 
that!. Well, the spec is not very clear on this and allows the context node to 
be selected using the selector, which results a single node in the target node 
set. So, how do you enforce uniqueness in a single node. A point to be addressed 
by the spec.

Your schema is valid, but to enforce the uniqueness, you have to declare the 
unique in the parent of 'Fact' element, so that the selector xpath can select a 
set of 'Fact's and can enforce uniqueness in a set of 'Fact's:

 <element name="Facts" type="fac:FactsType">
    <unique name="factID">
     <selector xpath="./fac:Fact"/>
     <field xpath="fac:UniqueID"/>

Hope that helps.

Received on Sunday, 21 April 2002 02:12:59 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:56 UTC