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

Multi-field Key definition using parent and child fields?

From: Barclay Alan K Contr AEDC/DYN <Alan.Barclay@arnold.af.mil>
Date: Tue, 2 Nov 2004 23:00:20 -0000
Message-ID: <200411022300.iA2N0h7x009925@andes.arnold.af.mil>
To: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
I have a schema that has a many2many relationship as follows:
 
 
Root----X----Y
      |
      |-A----B
 
 
Where all are 1..N and B has a multiple field foreign key-type relationship
whose keys are X and Y.
 
(In reality, B also has another foreign key relationship with A, but it is
express compositionally rather than with key/keyref - i.e. by the
parent-child relationship.)
 
In an RDBMS, the B table would Look like (BPK,AFK,XFK,YFK) where the last
two fields (XFK,YFK) would be a single multi-field foreign key.
 
I have been able to solve this if I replicate the XPK value in the Y Node
(i.e. Y-Node has XPK and YPK elements where the XPK is simply a copy of the
parent value). 
Basically, I have a Key at Root similar to:
  <xs:key name="XYKEY">
   <xs:selector xpath="./X/Y"/>
   <xs:field xpath="XID"/>
   <xs:field xpath="YID"/>
  </xs:key>
 
and a 2-field unique and 2-field keyref at A:
     <xs:keyref name="XYKEYREF" refer="XYKEY">
      <xs:selector xpath="./B"/>
      <xs:field xpath="BFK1"/>
      <xs:field xpath="BFK2"/>
     </xs:keyref>
     <xs:unique name="NoDups">
      <xs:selector xpath="B"/>
      <xs:field xpath="BFK1"/>
      <xs:field xpath="BFK2"/>
     </xs:unique>

This works and validates just like I want, however I have to duplicate the
X-value in the Y node.
 
Is there any way to specify a multi-field Key whose uniqueness is on the
combined values in the parent and child?
 
E.g. 
<Root>
  <X>
     <XID>1</XID>
     <Y>
        <YID>1</YID>
     </Y>
     <Y>
        <YID>2</YID>
     </Y>
  </X>
  <X>
     <XID>2</XID>
     <Y>
        <YID>1</YID>
     </Y>
     <Y>
        <YID>3</YID>
     </Y>
  </X>
  <A>
     <B>
        <BFK1>1</BFK1>
        <BFK2>1</BFK2>
        <Value>V1</Value>
     </B>
     <B>
        <BFK1>2</BFK1>
        <BFK2>2</BFK2>      <==== Would Fail to validate here.
        <Value>V2</Value>
     </B>
  </A>
</Root>
 
Thanks,
-Alan
Received on Tuesday, 2 November 2004 23:02:45 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 23:40:23 UTC