Jump to content

Convert XML to mySQL Result


bornecw

Recommended Posts

Hello everyone.  I have a PHP app that is all set up.  I'm getting some XML data from another source.  Since my app already processes all of the PHP using mySQL results, I'd like to convert the XML to a mySQL result.  That way I do not have to change the code in the rest of the app.  If the XML were something like:

<rec>

  <row>

    <name>Joe</name>

    <city>Houston</city>

  </row>

  <row>

    <name>Steve</name>

    <city>Dallas</city>

  </row>

</rec>

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/188207-convert-xml-to-mysql-result/
Share on other sites

I'd start by using explode on the xml string on the <row>, then looping the array using str_replace on the </row>, then do the same for <name> and <city> making an php array to hold all the data, then loop through this array to put the data how you need it.

I'd start by using explode on the xml string on the , then looping the array using str_replace on the , then do the same for and making an php array to hold all the data, then loop through this array to put the data how you need it.

 

Using arrays for XML parsing is very inefficient.

 

OP, I would look at simplexml or you can read this tutorial for more alternatives:

http://www.phpfreaks.com/tutorial/handling-xml-data

 

Hope this helps, although I'm not sure exactly what you mean by this:

 

I'd like to convert the XML to a mySQL result

 

@Maq - Sorry what I meant was converting xml into a resultset.  I have all this code that is already expecting the data in this way.  I am doing an interface with another client and they are sending xml.  If I can convert the xml to a resultset then there is very little that I have to do application wide.

@Maq - Sorry what I meant was converting xml into a resultset.  I have all this code that is already expecting the data in this way.  I am doing an interface with another client and they are sending xml.  If I can convert the xml to a resultset then there is very little that I have to do application wide.

 

The suggestions I proposed in my last post should suffice your needs.  There are plenty of examples, have a go.  If you need additional help, post back.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.