bornecw Posted January 12, 2010 Share Posted January 12, 2010 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 More sharing options...
gazever Posted January 12, 2010 Share Posted January 12, 2010 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. Link to comment https://forums.phpfreaks.com/topic/188207-convert-xml-to-mysql-result/#findComment-993630 Share on other sites More sharing options...
Maq Posted January 12, 2010 Share Posted January 12, 2010 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 Link to comment https://forums.phpfreaks.com/topic/188207-convert-xml-to-mysql-result/#findComment-993672 Share on other sites More sharing options...
bornecw Posted January 12, 2010 Author Share Posted January 12, 2010 @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. Link to comment https://forums.phpfreaks.com/topic/188207-convert-xml-to-mysql-result/#findComment-993679 Share on other sites More sharing options...
Maq Posted January 12, 2010 Share Posted January 12, 2010 @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. Link to comment https://forums.phpfreaks.com/topic/188207-convert-xml-to-mysql-result/#findComment-993680 Share on other sites More sharing options...
bornecw Posted January 12, 2010 Author Share Posted January 12, 2010 Thanks! Link to comment https://forums.phpfreaks.com/topic/188207-convert-xml-to-mysql-result/#findComment-993681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.