Hi Roberto,
   May be following new key and keyref definitions might work,

<xs:key name="PKAddresses1">
     <xs:selector xpath="Address"/>
     <xs:field xpath="Street"/>
     <xs:field xpath="City"/>
</xs:key>
<xs:key name="PKAddresses2">
     <xs:selector xpath="Address/AddressID"/>
     <xs:field xpath="."/>
</xs:key>
<xs:keyref name="FKStudentToAddress" refer="PKAddresses2">
     <xs:selector xpath="Student/AddressID"/>
     <xs:field xpath="."/>
</xs:keyref>

This can provide a new key for Address as you've written, but it seems
this new key can't be referentially related to Student elements (since
students don't have Street & City elements). Therefore, to maintain a
referential integrity between Address and Student, we need to keep
using AddressID elements.

I think, a sibling xs:field 's give an ordered semantics to a key (see
my new suggested key definition). We might like to make this semantics
unordered, and a corresponding referential integrity also. It seems,
XSD 1.1 can help with this requirement using assertions.

I haven't tested any of the above suggestions.

On Sat, Jun 1, 2013 at 7:43 PM, Roberto Marabini <robe...@cnb.csic.es> wrote:
> Hi,
>
>   I am trying to insert primary and foreign keys in a XSD schema.
>   I have been able to create the two attached files in which  students,
>   addresses and a  student/address relationship are defined.
>
>  An example of a student and address elements is:
>
> ====
>     <Student>
>         <Title>Title1</Title>
>         <FirstName>FirstName1</FirstName>
>         <LastName>LastName1</LastName>
>         <Dateborn>1900-01-01</Dateborn>
>         <Gender>Gender1</Gender>
>         <StudentID>StudentID2</StudentID>
>         <AddressID>AddressID1</AddressID>
>     </Student>
>     <Address>
>         <AddressID>AddressID1</AddressID>
>         <Street>Street1</Street>
>         <City>City1</City>
>         <Province>Province1</Province>
>         <Country>1900-01-01</Country>
>         <PostalCode>PostalCode1</PostalCode>
>     </Address>
>
> ================
>
> Now, I would like to use as key not "AddressID" but the pair ("Street","City")
> How should I modify the xsd file?
>
>          Thnaks in advance
>
>                 Roberto



-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-users-h...@xerces.apache.org

Reply via email to