Click to See Complete Forum and Search --> : recursive relationships
kfenstad
05-14-2003, 11:41 AM
hello,
i am *very* new to xml so please bear with me!
i know that i can create a schema that has a relationship where the same table is both parent and child. such as in an employee table, where there is both an emp id and then a supervisorid which references that emp id.
but if i had two tables... such as...
employee table
empid
name
...
supervisor table
empid
supervisorid
how could i create a schema from these? any help would be appreciated... thanks. :)
kfenstad
05-15-2003, 08:12 AM
maybe a clearer example...
schema from one employee table...
<xsd:schema xmlns:sql="urn:schemas-microsoft-com:mapping-schema" xmlns:dt="urn:schemas-microsoft-com:datatypes" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:appinfo>
<sql:relationship name="emp_reportsTo"
parent="emp"
parent-key="empid"
child="emp"
child-key="reportsto" />
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="emp"
type="employeeType"
sql:key-fields="empid"
sql:relation="emp"
sql:limit-field="reportsto"/>
<xsd:complexType name="employeeType">
<xsd:sequence>
<xsd:element name="Employee"
type="employeeType"
sql:relation="emp"
sql:relationship="emp_reportsTo"
sql:key-fields="empid"
sql:max-depth="6" />
</xsd:sequence>
<xsd:attribute name="ID" sql:field="EmpID" sql:datatype="int" />
<xsd:attribute name="Title" sql:field="Title" sql:datatype="varchar" />
</xsd:complexType>
</xsd:schema>
resulting in a tree like...
<response xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<emp Title="President" ID="1">
<Employee Title="VP" ID="2">
<Employee Title="Sales Manager" ID="3">
<Employee Title="Sales" ID="5"/>
<Employee Title="Sales" ID="6"/>
<Employee Title="Sales" ID="7"/>
</Employee><Employee Title="IT Manager" ID="4">
<Employee Title="IT" ID="8"/>
<Employee Title="IT" ID="9"/>
</Employee>
</Employee>
</emp>
</response>
but i need to do this using two tables instead.