Dustin013 Posted February 10, 2009 Share Posted February 10, 2009 What is the correct method for reading an xml response from a server that replies using a small XML file in response to a post request sent from a form? <!DOCTYPE response SYSTEM "https://blah/ap/dtd/response-v2.dtd"> <response> <result>success</result> <data>data here</data> <Id>0000</Id> <url><![CDATA[https://blahblah.com/lead?action=show&variable=0000]]></url> </response> Quote Link to comment https://forums.phpfreaks.com/topic/144698-reading-xml-response/ Share on other sites More sharing options...
premiso Posted February 10, 2009 Share Posted February 10, 2009 simplexml Would be my answer. Quote Link to comment https://forums.phpfreaks.com/topic/144698-reading-xml-response/#findComment-759300 Share on other sites More sharing options...
Dustin013 Posted February 10, 2009 Author Share Posted February 10, 2009 Ok, I have a form, it makes a post to a URL, can you give me an example of how I am going to be able to get the script to read the response? I can see the response as shown above in Firebug, but I am trying to figure out how to get the script that is submitting the form to read the response. I know how to parse the data but not exactly sure how to grab the information the server is responding with. Quote Link to comment https://forums.phpfreaks.com/topic/144698-reading-xml-response/#findComment-759308 Share on other sites More sharing options...
gizmola Posted February 11, 2009 Share Posted February 11, 2009 Your script really needs to act as a client, submitting the form contents via a POST and then accepting the response from the server. This is quite complicated stuff. The best advice I have is to use PHP's curl integration. http://www.php.net/curl Basically what you would need to do: 1. Form posts either to itself or to another script 2. Use Curl to re-post to the target server 3. Curl will let you read the response data 4. Parse that into something you can use with simplexml or whatever other PHP/xml solution suites you. Quote Link to comment https://forums.phpfreaks.com/topic/144698-reading-xml-response/#findComment-759335 Share on other sites More sharing options...
Dustin013 Posted February 11, 2009 Author Share Posted February 11, 2009 Thanks for the help, I ended up using the following... $xmlFileData = file_get_contents($url); $xmlData = new SimpleXMLElement($xmlFileData); etc.. and got it to work great ;-) Quote Link to comment https://forums.phpfreaks.com/topic/144698-reading-xml-response/#findComment-759404 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.