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

Re: Selector Clarification

From: Rahul Srivastava <Rahul.Srivastava@Sun.COM>
Date: Mon, 8 Apr 2002 15:01:27 +0000 (Asia/Calcutta)
Message-Id: <200204080938.g389ctF19146@blr-root.India.Sun.COM>
To: jeni@jenitennison.com
Cc: xmlschema-dev@w3.org
Thanks Jeni for the quick reply. 
As always your explainations are clear, non ambigous and wonderful.

Cheers,
Rahul.

> Date: Mon, 8 Apr 2002 10:12:25 +0100
> From: Jeni Tennison <jeni@jenitennison.com>
> 
> Hi Rahul,
> 
> > I have two small schemas for an instance file defining Id/y
> > constraints. One works and the other does not. I doubt the other one
> > is invalid.
> 
> You're correct that it isn't invalid, but it doesn't do what you want
> it to do. Looking at the one that works first:
> 
> > schema1: This works
> >
> > <xsd:element name="root">
> >   <xsd:complexType>
> >     <xsd:sequence>
> >       <xsd:element name="Book" maxOccurs="unbounded">
> >         <xsd:complexType>
> >           <xsd:sequence>
> >             <xsd:element name="isbn" type="xsd:string"/>
> >           </xsd:sequence>
> >           <xsd:attribute name="name" type="xsd:string" use="required"/>
> >         </xsd:complexType>
> >       </xsd:element>
> >     </xsd:sequence>
> >   </xsd:complexType>
> >
> >   <xsd:key name="BookKey">
> >     <xsd:selector xpath="./Book"/>
> >     <xsd:field xpath="isbn"/>
> >   </xsd:key>
> >
> > </xsd:element>
> 
> The key says:
> 
>   "Within each <root> element, every <Book> element child of that <root>
>    element must have a unique value for its child <isbn> element."
> 
> In other words, no two <Book> elements within the <root> element can
> have the same value for their <isbn> element child.
> 
> On the other hand, in the one that doesn't work:
> 
> > schema2: This does not works
> >
> > <xsd:element name="root">
> >   <xsd:complexType>
> >     <xsd:sequence>
> >       <xsd:element name="Book" maxOccurs="unbounded">
> >         <xsd:complexType>
> >           <xsd:sequence>
> >             <xsd:element name="isbn" type="xsd:string"/>
> >           </xsd:sequence>
> >           <xsd:attribute name="name" type="xsd:string" use="required"/>
> >         </xsd:complexType>
> >
> >         <xsd:key name="BookKey">
> >           <xsd:selector xpath="."/>
> >           <xsd:field xpath="isbn"/>
> >         </xsd:key>
> >
> >       </xsd:element>
> >     </xsd:sequence>
> >   </xsd:complexType>
> > </xsd:element>
> 
> The key says:
> 
>   "Within each <Book> element, that <Book> element itself must have a
>    unique value for its <isbn> element child."
> 
> All that this actually tests is that the <Book> element doesn't have
> two <isbn> element children. You are only testing whether one <Book>
> element has a unique value.
> 
> The location of the identity constraint determines the scope in which
> it holds; the selector selects the elements that should have unique
> values; the fields select the attributes and elements of those
> elements that should be combined to give the unique values.
> 
> Basically, the only reason you'd ever want to use an XPath of '.'
> within xs:selector is if you were using the identity constraint as a
> hack to test a co-occurrence constraint.
> 
> Cheers,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/


Sun Microsystems, Inc.
Received on Monday, 8 April 2002 05:39:01 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:30 GMT