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

Re: [Moderator Action] Re: [Moderator Action] Key/Keyref definition

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 18 Apr 2001 10:31:35 +0100
To: "Ravindra Jain" <ravindra@ltp.soft.net>
Cc: <xmlschema-dev@w3.org>
Message-ID: <f5bitk2mu4o.fsf@cogsci.ed.ac.uk>
"Ravindra Jain" <ravindra@ltp.soft.net> writes:

> Thanks Henry,
> your explanation helped me a lot in understanding validation rules for
> identity-constraints.
> But now I have doubt about where in the schema FILE, the key should be
> defined.
> For example, suppose a keyref is defined in some element.
> Now the key referred in the keyref MUST be defined "either within the same
> element, or somewhere deep inside that element."
> I mean to say that it can not be defined in some element which is not a
> child (direct or indirect) of this current element (where keyref is being
> defined).
> Am I correct ?

Yes.

> The example given in XML Schema Part 1: structures has this condition in it
> (which should be invalid according to my understanding)
> Here is the relevent part of that example :
> 
> "<element name="state">
>      <complexType>
>           <sequence>
>               <element name="code" type="twoLetterCode"/>
>               <element ref="vehicle" maxOccurs="unbounded"/>
>               <element ref="person" maxOccurs="unbounded"/>
>          </sequence>
>      </complexType>
> 
>     <key name="reg">   <!-- vehicles are keyed by their plate within
> states -->
>           <selector xpath=".//vehicle"/>
>           <field xpath="@plateNumber"/>
>      </key>
> 
>     <keyref name="vehicleState" refer="state">
> 
>           <!-- every vehicle refers to its state -->
>           <selector xpath=".//vehicle"/>
>           <field xpath="@state"/>
>      </keyref>
> </element>
> 
> <element name="root">
>      <complexType>
>          <sequence>
>                . . .
>                <element ref="state" maxOccurs="unbounded"/>
>                . . .
>          </sequence>
>      </complexType>
> 
>     <key name="state">     <!-- states are keyed by their code -->
>           <selector xpath=".//state"/>
>           <field xpath="code"/>
>     </key>
> 
>     <key name="regKey">    <!-- vehicles are keyed by a pair of state and
> plate -->
>           <selector xpath=".//vehicle"/>
>           <field xpath="@state"/>
>           <field xpath="@plateNumber"/>
>     </key>
> 
>     <keyref name="carRef" refer="regKey"> <!-- people's cars are a
> reference -->
>           <selector xpath=".//car[@regRef]"/>
>           <field xpath="@regState"/>
>           <field xpath="@regPlate"/>
>     </keyref>
> </element>"
> 
> In this example, keyref (vehicleState) defined inside the "state" element
> refers to a key (state), which is defined inside the "root" element.
> and the "root" element is not a child of "state" element. However, the
> opposite is true, i.e. "state" is a child of "root" ( "root" refers to
> "state")
>
> so is it valid ?
> and if yes, then what is the rule for defining a key in the schema file.

Oops.  Thanks for spotting that, that example has been changed too
many times.  That keyref shoud be declared within "root" -- I'll fix
it.

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
Received on Wednesday, 18 April 2001 05:31:35 GMT

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