[
Lists Home |
Date Index |
Thread Index
]
The caveat is that both ID/IDREF and key/keyref only operate on a single XML document not on multiple docs. It looks that this is fine in this case but not a general solution for situations where each table is represented by an XML document.
-----Original Message-----
From: CHIUSANO, Joseph [mailto:JCHIUSANO@lmi.org]
Sent: Wed 7/31/2002 1:49 PM
To: 'Mudita Singhal'; xml-dev@lists.xml.org
Cc:
Subject: RE: [xml-dev] Doubt
Mudita,
You can use the ID/IDREF technique in the DTD - i.e. an attribute of type "ID" would represent the primary key value, and an attribute of type "IDEF" would represent the foreign key value. The one-to-many relationship would therefore be ID-to-IDREF. Please note that there are some disadvantages to this approach:
(1) An ID-type attribute value cannot begin with a number;
(2) An ID-type attribute value can appear only once within an XML document (however, IDREF-type attribute values can appear multiple times);
(3) An XML processor will not validate the associations between ID and IDREF values. That is, if A.1 contains the value "A123" and there is a B.2 (IDREF) value of "A123", that is great. However, if there is a value of "A123" for another IDREF-type attribute (perhaps C.2 instead of B.2), an XML processor will be happy with this even though the association is incorrect.
To avoid these issues, you can use XML Schema and the KEY/KEYREF mechanism. In addition to avoiding (1) and (2) above, you can explicitly declare associations between elements or attributes - so you can ensure that (for instance) when there is a value of "A123" for an A.1 attribute, there must be a matching value of "A123" for a B.2 attribute (not just any attribute in the XML document).
Hope that helps,
Joe Chiusano
LMI
> **************************************************************************
> Joseph M. Chiusano
> Logistics Management Institute
> 2000 Corporate Ridge
> McLean, VA 22102
> Email: jchiusano@lmi.org
> Tel: 571.633.7722
> **************************************************************************
>
-----Original Message-----
From: Mudita Singhal [mailto:msinghal3@rediffmail.com]
Sent: Wednesday, July 31, 2002 4:12 PM
To: xml-dev@lists.xml.org
Subject: [xml-dev] Doubt
Hello all,
I am new to this group and so might be asking a question which
might ahve already been answered, or is very simple.Sorry for
that.
If we have to make a DTD for a database with 2 tables, say A and
B.The attributes of the tables are as under:
Table A
A.1(PRIMARY KEY)
A.2
A.3(FORIEGN KEY TO TABLE B)
Table B
B.1(PRIMARY KEY)
B.2(foriegn key to table A)
Now can anyone guide me on how to write a simple DTD for
this.Means , do we have to declare a content type declaration for
the forign keys also??IF not then how do we write the XML document
for this?
secondly How to impose the many-to-many and one-to-many
relationships?
Thanks
Mudita
-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>
The list archives are at http://lists.xml.org/archives/xml-dev/
To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl>
|