Hi Luca,
You can use LOAD_FILE() to read the XML file as a string, then use XPath functions to parse it and insert the data from the XML elements and attributes into one or more tables.
In 5.1.20 and newer, this job is can made easier with user variables in XPath expressions. See
http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html for more info about the XPath functions. It's on my TODO to add some more examples, but there should be enough there to get you started.
If you want to build a 5.2 server, you can import XML much more easily using LOAD XML INFILE, which is documented here:
http://dev.mysql.com/doc/refman/5.2/en/load-xml.html - if you use the BUILD/compile-* script appropriate to your platform, the new statement should be enabled.
(LOAD XML will almost certainly NOT be added to 5.1, since 5.1 is already in beta.)
You can grab the 5.2 source from
http://mysql.bkbits.net/ (yes, Virginia, there is a 5.2 tree, but there's no binaries yet, and probably won't be for a while). LOAD XML seems to work pretty well - well enough that I didn't run into any major problems playing with it whilst writing the documentation. Of course, if you go that route, we'd appreciate it if you file bugs against any issues you might encounter. :)
Good luck!
Jon Stephens
MySQL Documentation Team @ Oracle
MySQL Dev Zone
MySQL Server Documentation
Oracle
Edited 1 time(s). Last edit at 08/26/2007 01:44PM by Jon Stephens.