tags:

views:

47

answers:

2

Hey
I want to store the contents of an xml file in the database. Is there an easy way to do it? Can i write some script that can do the task for me?

The schema of the XML file looks like this:

<schedule start="20100727120000 +0530" stop="20100727160000 +0530" ch_id="0210.CHNAME.in">
    <title>Title_info</title>
    <date>20100727</date>
    <category>cat_02</category>
  </schedule>

One thing to note is:
How do I read the start time? I need the time +0530 added to the time?

Thank you so much.

A: 

look up simple_xml on the php page - off hand I'm not too hot on it, but basically you will end up with a loop which will add your data to an object eg:

$xml

and you will be able to call tags as such $xml->schedule->title $xml->schedule->date and $xml->schedule->category and you will be able to call attributes as such $xml->schedule[start] but you might wanna check that.

I had to do this recently for a client, and this was the best way I could find. The attributes may be tricky - I can't quite remember but you might have to look into namespaces and such... anyway, find simple_xml and you're on the right tracks.

Thomas Clayson
+1  A: 

You'll probably want to create a table called schedules that matches your data, then read the contents of the XML file with an XML parser of your choice. SimpleXML might be the right tool for this job.

As for the dates, I recommend you try using the function date_parse_from_format().

Kaivosukeltaja