How to output data in xml?

Trying to wrap my head around importing XML data into a PHP script using SimpleXML?

  • I have an XML file which I need to import, extract data, and then enter that data into my data base. I'm playing around with SimpleXML functions, but I haven't been able to figure anything out yet. This is the basic format of my XML file: <fandango data> .....<movies> ..........<movie> ...............<movie_id> ...............<movie_title> ..........</movie> .....</movies> .....<sessions> ..........<session> ...............<session_id> ...............<movie_id> ...............<date_time> ..........</session> .....</sessions> </fandango data> I'm not looking for someone to write a script for me, just some help importing the data from the .xml file into arrays and/or variables.

  • Answer:

    Hi there. There way SimpleXML works is that it parses the XML file and then stores the XML data in an object. The simple XML functions are used to fetch specific pieces of data from the object (such as <movie_id> in your example). I'm not sure how much you've discovered about SimpleXML, but this is the way I would go about doing it: 1. Create your SimpleXML object 2. Create various variables that contain the results of SimpleXML functions (in other words, store the parsed data of the XML in variables) 3. Whatever code you want to enter the data into the database The downside to using SimpleXML, however, is that you would need to write a recursive function in order to get data that is more than two levels down in the XML tree. This isn't too hard to do though. Experimenting with SimpleXML is the hardest part, once you've understood, it's pretty...well, simple!

Justin H at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.