Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Saving XML Data into a Table

Well, one can ask a general question: how do we map XML-like data to a relational
database?

It is not that complicated if we take a relatively abstract look into the
nature of the data in XML - there are two types of relationships: "is-an-element-of"
and "is-an-attribute-of"; normally I would also separate attribute values
as very separate entities. Thus we have three tables: entities (a.k.a. elements),
properties (a.k.a. attributes) (name-value-owner triples), and "is-an-element-of"
many-to-one map.

In a relational database all these guys should of course have unique ids,
which are meaningless outside (in XML), since relationships become physical
once we export the data.

I implemented this a while ago, adding some inessential tricks for efficiency
- well, it worked.

The think one needs least here is a dtd or a schema. These are a threat to
our freedom.
[941 byte] By [Vlad Patryshev] at [2007-11-9 15:27:29]
# 1 Re: Saving XML Data into a Table
Very intriguing, Vlad, but a bit sketchy. How do you handle the recursive,
i.e., unknown depth, issues? How do you walk the tree? As I recall, Oracle
has a bill-of-materials facility that understands parent and child, but I
haven't used it for years. Does SQLserver have something to handle recursion?
David Hopp at 2007-11-11 23:29:47 >
# 2 Re: Saving XML Data into a Table
"David Hopp" <dhopp@cato.com> wrote:
>
>Very intriguing, Vlad, but a bit sketchy. How do you handle the recursive,
>i.e., unknown depth, issues? How do you walk the tree? As I recall, Oracle
>has a bill-of-materials facility that understands parent and child, but
I
>haven't used it for years. Does SQLserver have something to handle recursion?

David, any unknown depth consists of repetition of the same kind of relationship,
right? This means that we only have to register "parent-child"-like relationsships.
Actually, in real life, there are more, and an element can be a member of
different collections. This still can be reflected in an XML (but this goes
in the opposite direction now.)

I have a sketch of an article on this here: http://www.patryshev.com/dev/GenericDB/GenericDataModel.htm;
there was an implementation too that worked at least with mySQL... as if
anybody was interested. :) The time for it seems to have gone now, with native
XML databases appearing all around.
Vlad Patryshev at 2007-11-11 23:30:53 >