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

Re: Constraint Specifications in XML Schemas

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 01 Nov 2002 08:51:08 +0000
To: "Alexandre Martins" <alex.martins@netc.pt>
Cc: <xmlschema-dev@w3.org>
Message-ID: <f5bn0ot1xmr.fsf@erasmus.inf.ed.ac.uk>

You can get close to what you need, but without chained keyrefs, which
we don't (yet) support, not all the way.

Add the following to get close:

1) to the elt decl for Database
 <xs:key name="table">
  <xs:selector xpath="Table"/>
  <xs:field xpath="@id"/>
 </xs:key>
 <xs:keyref name="foreign1" refer="table">
  <xs:selector xpath=".//ForeignTable"/>
  <xs:field xpath="@tableId"/>
 </xs:keyref>
 <xs:keyref name="foreign2" refer="field">
  <xs:selector xpath=".//ForeignField"/>
  <xs:field xpath="@fieldId"/>
 </xs:keyref>

2) to the elt decl for Table
 <xs:key name="field">
  <xs:selector xpath="Field"/>
  <xs:field xpath="@id"/>
 </xs:key>
 <xs:keyref name="local1" refer="field">
  <xs:selector xpath=".//KeyField"/>
  <xs:field xpath="@fieldId"/>
 </xs:keyref>
 <xs:keyref name="local2" refer="field">
  <xs:selector xpath=".//FieldRef"/>
  <xs:field xpath="@fieldId"/>
 </xs:keyref>
  
What's imperfect about this is that it doesn't check (because it
can't) that the foreign field is in the right foreign table.  The
real downside of this is that if their are two fields with the same
name in different tables, foreign key refs to them will be spuriously
identified as errors.

Hope this helps,

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2002, 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/
 [mail really from me _always_ has this .sig -- mail without it is forged spam]
Received on Friday, 1 November 2002 04:03:35 GMT

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