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

RE: Identity Constraints

From: Mark Thornton <mthornton@optrak.co.uk>
Date: Fri, 8 Mar 2002 10:07:25 -0000
Message-ID: <30273167BD5AD111A5AD00A0C9922017537464@mercury.net.optrak.co.uk>
To: "'Jeni Tennison'" <jeni@jenitennison.com>
Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
The data I have looks like this:

<table name='addresses'>
	<column name='street'/>
	<column name='town'/>
</table>

then elsewhere

<table ref='addresses'>
	<column ref='street'/>	<!-- refer to the street column defined
earlier -->
	<column name='country'/> <!-- adds a new column to the 'addresses'
table -->
</table>

So ideally I would do something like

<xs:key name='kColumn'>
	<xs:selector xpath='table'/>
	<xs:field xpath='@name|@ref'/>
	<xs:field xpath='column/@name'/>
</xs:key>

<xs:keyref name='dummy1'>
	<xs:selector xpath='table'/>
	<xs:field xpath='@name|@ref'/>
	<xs:field xpath='column/@ref'/>
</xs:keyref>

There would also be identity constraints on the table names, but that isn't
a problem.

Thanks for your help,
Mark Thornton

-----Original Message-----
From: Jeni Tennison [mailto:jeni@jenitennison.com]
Sent: 08 March 2002 09:48
To: Mark Thornton
Cc: 'xmlschema-dev@w3.org'
Subject: Re: Identity Constraints


Hi Mark,

> I am rather confused by some types of multi field identity
> constraints. The example in the schema primer: (at
> http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness)
>
> <unique name="dummy1">
>   <selector xpath="r:regions/r:zip"/>
>   <field    xpath="@code"/>
>   <field    xpath="r:part/@number"/>
>  </unique>
>
> seems to be what I want, BUT I can't reconcile this with the
> validation rules in the standard (3.11.4):
>
> "3 For each node in the Ětarget node setĚ all of the {fields}, with
> that node as the context node, evaluate to either an empty node-set
> or a node-set with exactly one member, which must have a simple
> type."
>
> Specifically the second field would appear to have multiple values
> for a single node in the target set (a 'zip' element).

I agree. I think that this is an error in the example in the Primer.
The identity constraint would, however, be legal if the XML document
instead included:

 <regions>
  <zip code="95819">
   <part number="872-AA" quantity="1"/>
  </zip>
  <zip code="95819">
   <part number="926-AA" quantity="1"/>
  </zip>
  <zip code="95819">
   <part number="833-AA" quantity="1"/>
  </zip>
  <zip code="95819">
   <part number="455-BX" quantity="1"/>
  </zip>
  <zip code="63143">
   <part number="455-BX" quantity="4"/>
  </zip>
 </regions>

As the XML document (4Q99.xml) currently stands, I think what's needed
is two identity constraints, one to check that all zip elements within
the regions element have unique code attributes:

  <xs:unique name="uniqueZips">
    <xs:selector xpath="r:zip" />
    <xs:field xpath="@code" />
  </xs:unique>

And one, defined within the element declaration for the zip elements,
to check that each part element has a unique number attribute:

  <xs:unique name="uniqueParts">
    <xs:selector xpath="r:part" />
    <xs:field xpath="@number" />
  </xs:unique>

Of course this won't work if you want to allow multiple zips with the
same code, e.g.:

 <regions>
  <zip code="95819">
   <part number="872-AA" quantity="1"/>
   <part number="926-AA" quantity="1"/>
  </zip>
  <zip code="95819">
   <part number="833-AA" quantity="1"/>
   <part number="455-BX" quantity="1"/>
  </zip>
  <zip code="63143">
   <part number="455-BX" quantity="4"/>
  </zip>
 </regions>

I don't think that it's possible to create an identity constraint for
that kind of structure using XML Schema.

> Is there a good explanation anywhere of the use of identity
> constraints where the fields are not all at the same depth?

If you describe what you want to check we should be able to help, or
tell you if it isn't possible.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Friday, 8 March 2002 05:08:02 GMT

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