![](bg6.png)
the values of the previous visited key nodes, prof-id
= P1, course-id = C1 and student-id = S1:
As score and result are leafs, their tags are added to
the tag created by student-id node:
Although the graph traversal is finished at this point,
the created XML document contains only data about
professor P1, course C1 and student S1. Then, for
translating available data about the other elements,
we must revisit previous visited branches starting
with key attributes from right to left in order to take
into account all possible combinations of values of
these three attributes in the database. According to
the scores table, such combinations are:
Now we come back to the last visited branch starting
with a key attribute, student-id, whose next value is
S2 and we re-traverse all subsequent graph nodes. At
this point, all values of student-id will be analyzed,
then we come back to the prior branch, course-id. Its
next value is C2. Again, all remaining branches are
visited. The translation is complete when the graph
is traversed for all of the combinations above.
The complete algorithm for generating an XML
document from a relational database is presented in
figure 4.
5 RELATED WORK
The translation of relational data into XML has been
addressed by many researchers. Table-centered-only
approaches are rare (Turau, 1999). On the other
hand, entity-centered approaches are numerous. In
XPERANTO (Carey et al. 2000) and SilkRoute
(Fernandez, Suciu & Tan, 2000; Fernandez et al.
2001) users can specify entity-centered XML views
over a relational database respectively through the
mapping languages XQuery and RXL (proprietary).
XML/SQL (Vittori, Dorneles & Heuser, 2001) is
another proprietary language which allows users to
define the structure of the final XML document, but
they must also specify SQL queries for retrieving the
data. In (Shanmugasundaram et al., 2000), SQL
language is extended with XML translation and
aggregation functions, but nestings in the final XML
document are defined by users through complicated
nested SQL queries. In (Lewis, 2002), users create a
DTD or an XML-Schema which describes the XML
document they need and the necessary SQL queries
are generated by the system, but users must avoid
demanding data from tables that can not be joined.
An hybrid table/entity-centered redundancy free
approach is proposed in (Liu C., Liu J. & Guo,
2003), where a relational schema is translated into
an XML-schema. NeT (Lee et al., 2001) and CoT
(Lee et al., 2002) algorithms take database create
statements as input. Then, the first creates a DTD by
using an operator which deduces cardinalities, but it
is only applicable to a single table at a time. The
second handles several tables but outputs data in a
proprietary language called XSchema. In (Kleiner &
Lipeck, 2001), the authors also propose an algorithm
for creating a DTD from an ER-Schema. However,
while their DTD starts only with entities that are not
functionally dependent on other ones, our DTD can
start with any data entity. Mapping rules are also
different: while we map data entities, attributes and
relationships into DTD elements and nestings, they
map them respectively into DTD elements, attributes
and nestings or elements.
B
SELECT score FROM scores WHERE (prof-id =
P1) AND (course-id = C1) AND (student-id = S1)
ok
SELECT result FROM scores WHERE (prof-id =
P1) AND (course-id = C1) AND (student-id = S1)
<prof>
…
<student>
…
<score> B </score>
<result> ok </result>
</student>
</
rof>
XML tags
created by score
and result nodes
prof-id = P1, course-id = C1, student-id = S1
prof-id = P1, course-id = C1, student-id = S2
prof-id = P1, course-id = C2, student-id = S1
prof-id = P2, course-id = C1, student-id = S3
6 CONCLUSION
We have presented two algorithms for translating the
structure and the content of a relational database
respectively into a DTD and an XML document.
They ensure the semantic correctness of the result by
respecting database functional dependencies thanks
to a directed graph indicating them. Additionally,
these algorithms can create different entity-centered
views of the same data. Finally, they require no user
intervention, nor intermediary languages specifying
mapping schemes. In the future, some improvements
can be made in order to reduce the redundancy in the
final XML document and the great number of SQL
queries executed against the database.
REFERENCES
Carey M., Florescu D., Ives Z. et. al., ‘XPERANTO:
Publishing Object-Relational Data as XML’,
Workshop on the Web and Databases, 2000.
KEYS GRAPH - BASED RELATIONAL TO XML TRANSLATION ALGORITHM
147