RE: Identity Constraints

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 UTC