Lists Home |
Date Index |
Maintaining primary key / foreign key relationships and enforcing
referential integrity are slightly different things.
Primary key / foreign key relationships are usually maintained in XML
documents by nesting or by explicit references. For example, suppose I
have the following tables:
Master (MasterID, ...)
Detail (MasterID, DetailID, ...)
You can show this relationship in XML through nesting:
or through explicit references:
<Detail MasterIDRef="..." DetailID="...">
Note that in the first case, the MasterID is listed only once. In the
second case, it is listed for each detail record.
As to referential integrity, the nesting structure essentially enforces
it, but the reference structure does not. That is, it is perfectly legal
for a MasterIDRef attribute to have a value not listed in any MasterID
attribute. Neither structure requires MasterID or DetailID attributes to
I suspect your instructor wants the relationships to be maintained,
rather than integrity to be enforced.
Marco Mastrocinque wrote:
> Hi All,
> Thanks for your help. It's for an assignment I'm doing. The lecturer
> states that I have to maintain referential integrity i.e. the Primary Key
> and Foreign Key relationships must be maintained in the resultant XML file.