"J Sharman" <joe@joesharman.co.uk> wrote in message news:<bfmqod$d3a$1@titan.btinternet.com>...[color=blue]
> What is the easiest way to import an XML Datafeed from a URL into a MYSQL
> Database? Possibly using PHP
>
> Regards Joe
>
> PS Please answer to group and
joe@joesharman.co.uk[/color]
I don't think there is an easy way. XML is like a freeform n-ary
tree, where each node has any number of children.
You could model that with some sort of node structure that
holds an array of pointers to all its children.
Alternately (and easier to implement with sql) you could model
nodes in an XML tree as relational tables where each
node (each table) holds a numerical
primary key plus a foreign key pointer to that node's parent.
Something like the following:
create table node
(
nid int primary key auto_increment, #pk for this node
rid int references node(nid),#points to the root node of tree
pid int references node(nid),#points to this node's parent
name VARCHAR(48) not null,
xpath VARCHAR(128), #the xpath to the node
value TEXT,
indexes(??)
)
For any database that really supports foreign keys,
you'd have trouble with the recusive node assigments
above: at least when you tried to initialize the root
node of a tree (real foreign keys have to point to
already existing keys).
So for Oracle or Postgres, you have to initialize the
table without the foreign key constraints, and
then add the fk attributes with an 'altertable'
command--after inserting the data.
Sql joins over a table like that are a nightmare, however.
The best solution is to forget about relational databases
and use a native XML database. Then you can query the tree
with XPath statements and/or XQuery, which were designed
with tree-like data in mind.