tags:

views:

69

answers:

3

I have a question. Does anyone have a working php script which can parse a XML file to a sql database? I have searched for some scripts and didn't find anything what looks like I can edit it to my needs.

Any help would be great!

+2  A: 

Parse the XML using simplexml and extract the data of your interest from the XML file and insert into MySql using functions listed here.

Give it a try. Its not that difficult and you'll learn a lot.

codaddict
haha.. I dont know how to do this, isn't there a program what can help me do this?
Chris
A: 

Why not write one from scratch? Not that hard.

boxoft
I guess a couple of pointers as to how to do this wouldn't have gone amiss here ;-)
richsage
Recommend a tutorial "XPath in SimpleXML" at http://www.dimuthu.org/blog/2008/09/30/xpath-in-simplexml/.You can parse an XML file with regex instead of XPath if you like.After parsing the XML with XPath or regex, you can design a database table according to the relevant fields and import the extracted fields into the table.
boxoft
A: 

It is not a PHP solution, but you can extract values from XML directly into mySQL:

http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html

Of course, if this is something you will need to do often, you can always fall back to what bzabhi have said.

Rilindo
Actually, this does have PHP code to parse the XML file. Heh.
Rilindo