next up previous contents
Next: Database libraries Up: nodeXML version 3.* - Previous: How to use nodeXML


Map files and database relations

As described above, a map file links an XML file structure to actual data contained in a database. We return again on the MESSAGE example:
<MESSAGE>
	<FROM>sender</FROM>
	<TO>to</TO>
	<CONTENT>text</CONTENT>
</MESSAGE>
Every database field is referenced within an element content, but it is also possible to define maps that use XML attributes, like
<MESSAGE>
	<FROM RECEIVED_FROM="to">sender</FROM>
	<CONTENT>text</CONTENT>
</MESSAGE>
The RECEIVED_FROM attribute is linked to "to" field. Attributes can be used for search parameters as well as elements.

These two maps relate on the fact that every data is contained in the main table. nodeXML can also manage three different situations:

  1. there is no field in the database corresponding to the specified element;
  2. the element has to be filled with a field that is not contained in the main table, but is connected to it via a one-to-one relation;
  3. the element has to be filled with a field that is not contained in the main table, but is connected to it via a one-to-many relation.
Let's begin from the first case. It is possible to use a constant comment to fill the content of an element that can't refer to actual database data. For example, if the node has an archive of anonymous messages, but it still wants to match the prevoiusly defined MESSAGE structure, it is possible to define a map with the followin FROM element:
<FROM>%anonymous</FROM>
Percentage (%) character indicates that the content is not in the database, but instead it is the following string. In the example of anonymous messages, the node output will have a
<FROM>anonymous</FROM>
element for every record.

In the situation described in the second point the following information is needed to retrieve data: the name of the table containing the field (say T), the name of the field (F3), the name of the field in table T that estabilishes the relation (F2) and the corresponding field in the main table (F1). The sintax for the one-to-one relation is the following:

<FROM>otoo(F1,T,F2,F3)</FROM>
Finally, in the third case, we suppose that the one-to-many relation is implemented with a cross-relation table between the main table and the one containing the required field. Sintax is
<FROM>otom(F1,T1,F2,F3,T2,F4,F5)</FROM>
where F5 is the required field, F4 is the field which links the target table T2 with the cross-relation one (T1), matching with F3 field. F2 is the T1 field that links the cross-relation table with the main one matching with F1.


next up previous contents
Next: Database libraries Up: nodeXML version 3.* - Previous: How to use nodeXML
nodeXML manual main page