| home / authoring / languages / xml / databases / chap2 / 2 |
[previous] |
|
Adding ID AttributesThe next step is to create an ID attribute for each of the structural (nondata point) elements we have defined so far in our XML database (with the exception of the root element). This is to uniquely identify elements that need to be referred to by other elements. For the name of the attribute, we use the element name followed by ID. This might cause name collisions with other attributes that have already been added to the XML, in which case we need to change the names of these as appropriate. These should be defined as being of type ID, and must be declared as #REQUIRED. If we add these ID attributes to each element for now, we can optionally remove some from the created XML structures when we come to model all of the relationships. When populating these structures, a unique ID will need to be created for each instance of an element that is generated. We need to ensure that these IDs are unique not only across all elements of a specific type, but across all elements in our document. One way to do this programmatically (assuming that we're using automatically incremented integers for the primary keys in our database) is to use the primary key for the row being created, prefixed by the name of the table in which it appears. For example, for the customer in our database with the ID number 17, we might use the string Customer17 for the value of the CustomerID attribute on the Customer element. If we have nonnumeric keys in our database, or similar table names with numeric suffixes (like Customer and Customer1), this may cause name collisions - as always, be on the look out for these. In our example, then, we have:
|
| home / authoring / languages / xml / databases / chap2 / 2 |
[previous] |
Created: May 09, 2001
Revised: May 09, 2001