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
Related Q & A:
- How to deploy a server script?Best solution by Stack Overflow
- How to call a function with parameter in a bash script?Best solution by tldp.org
- How do you submit a movie script?Best solution by Yahoo! Answers
- How to start creating a php script, that will be installed on many servers?Best solution by Stack Overflow
- How Can I Create an XML to Create a Menu?Best solution by Drupal Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.