Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.