| home / authoring / languages / xml / databases / chap2 / 3 |
[previous] |
|
Add Element Content to the Root Element When we created the root element for the DTD, and added child elements for tables, we did not define the content models for the elements in the DTD - we said we would cover that when looking at relationships, and here we are. The next rule, therefore, is to add the content model for the root element to the DTD. We should add element content that is appropriate for the type of information we are trying to communicate in our documents.
For our example, we decided that the primary concepts we want to convey are related to
the
Walk the Relationships The next rule is a little tricky. We need to walk the relationships between the table (or tables) to add element content or ID-IDREF(S) pairs as appropriate. This process is similar to the process we would use when walking a tree data structure – we navigate each of the relationships, then each of the relationships from the children of the previous relationships, and so on, until all the relationships contained in the subset of tables we have chosen to include in our XML document have been traversed. Relationships that lead outside of the subset of tables we're representing do not need to be traversed.
Again, when we have a choice of directions in which a relationship may be followed, we
do so in the direction that makes the most business sense - for example, we'll probably
need to go from One-to-One or One-to-Many Relationships First consider the case where a relationship is one-to-one or one-to-many in the direction we selected for the relationship traversal, and the relationship is the only one in the selected subset of tables where this table is the destination of a relationship traversal. Then we should represent the relationship by adding the child element as element content of the parent content. Assign the multiplicity of the element according to the following table:
For our example DTD, adding the containment relationships gives us the following:
Many-to-One or Multiple Parent Relationships If the relationship is many-to-one, or the child has more than one parent, then we need to use pointing to describe the relationship. This is done by adding an IDREF or IDREFS attribute to the element on the parent side of the relationship. The IDREF should point to the ID of the child element. If the relationship is one-to-many, and the child has more than one parent, we should use an IDREFS attribute instead.
Note that these rules emphasize the use of containment over pointing whenever it is possible. Because of the inherent performance penalties when using the DOM and SAX with pointing relationships, containment is almost always the preferred solution. If we have a situation that requires pointing, however, and its presence in our structures is causing too much slowdown in our processing, we may want to consider changing the relationship to a containment relationship, and repeating the information pointed to wherever it would have appeared before. Applying this rule to our example and adding IDREF/IDREFS attributes, we arrive at the following:
We're getting close to our final result, but there are still a couple of things we need to do to finalize the structure. We'll see how this is done in the next couple of sections. |
| home / authoring / languages / xml / databases / chap2 / 3 |
[previous] |
Created: June 07, 2001
Revised: June 07, 2001