Bifter Posted May 13, 2009 Share Posted May 13, 2009 Hi and thanks for looking, I send a request to an ADSL provider and a response is sent back to the browser in XML with this code: <?php function httpsPost($Url, $strRequest) { // Initialisation $ch=curl_init(); // Set parameters curl_setopt($ch, CURLOPT_URL, $Url); // Return a variable instead of posting it directly curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Active the POST method curl_setopt($ch, CURLOPT_POST, 1) ; // Request curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // execute the connexion $result = curl_exec($ch); // Close it curl_close($ch); return $result; } $url = 'xml.xps.murphx.com'; $strRequest = utf8_encode('<?xml version="1.0"?> <Request module="XPS" call="availability" id="8c4566926694d7227d9d73fd8c2acc5b" version="2.0.1"> <block name="auth"> <a name="username" format="text">xxxxxx</a> <a name="password" format="password">xxxxxxx</a> <a name="client-id" format="counting">xxx</a> </block> <a name="postcode" format="postcode">LU2 0JJ</a> <a name="detailed" format="yesno">Y</a> <a name="order-type" format="text">provide</a> </Request>'); $Response = httpsPost($url, $strRequest); echo $Response; ?> This will output the following in the browser: <?xml version="1.0" ?> - <Response id="8c4566926694d7227d9d73fd8c2acc5b"> - <block name="availability"> <a name="quick-result" format="counting">5</a> <a name="postcode" format="postcode">LU2 0JJ</a> - <block name="classic-qualification"> <a name="result-code" format="text">Z</a> <a name="fixed-rate" format="text">G</a> <a name="likely-max-speed" format="counting">2097152</a> <a name="rate-adaptive" format="text">G</a> </block> - <block name="exchange"> <a name="code" format="text">SMLT</a> <a name="name" format="text">LUTON</a> <a name="state" format="text">E</a> <a name="llu" format="yesno">Y</a> </block> - <block name="max-qualification"> <a name="rate-adaptive" format="text">G</a> <a name="likely-max-speed" format="counting">4096000</a> </block> </block> My problems being: 1 - how do I get only certain parts of the XML response to display in the browser? 2 - how do I style the responses in XSL - I can style a static XML page but can't get this to work through PHP as a request? 3 - Can you convert each individual xml response such as <block name="exchange"> -> <a name="code"> into a variable? if so how? Would be very grateful for anybody assistance in this. Thanks, B. Quote Link to comment https://forums.phpfreaks.com/topic/157957-solved-formatting-xml-requests/ Share on other sites More sharing options...
JonnoTheDev Posted May 13, 2009 Share Posted May 13, 2009 Look at PHPs simpleXML extension. You can parse the XML document. Quote Link to comment https://forums.phpfreaks.com/topic/157957-solved-formatting-xml-requests/#findComment-833141 Share on other sites More sharing options...
Bifter Posted May 13, 2009 Author Share Posted May 13, 2009 Look at PHPs simpleXML extension. You can parse the XML document. Thanks for your responce. I have come accross this but I cannot figure out how to get it to work with my code, posted earlier. Do you have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/157957-solved-formatting-xml-requests/#findComment-833183 Share on other sites More sharing options...
JonnoTheDev Posted May 13, 2009 Share Posted May 13, 2009 <?php $Response = httpsPost($url, $strRequest); // create xml object from response $xmlObj = simplexml_load_string($Response); ?> You can then work through the elements as an array. Checkout some of the examples http://uk2.php.net/manual/en/function.simplexml-load-string.php Quote Link to comment https://forums.phpfreaks.com/topic/157957-solved-formatting-xml-requests/#findComment-833189 Share on other sites More sharing options...
Bifter Posted May 13, 2009 Author Share Posted May 13, 2009 Thanks again - how ever i just get this - Call to undefined function: simplexml_load_string() Quote Link to comment https://forums.phpfreaks.com/topic/157957-solved-formatting-xml-requests/#findComment-833218 Share on other sites More sharing options...
w3evolutions Posted May 13, 2009 Share Posted May 13, 2009 What version of php are you using and is simpleXML installed? You can run phpinfo() and check. Quote Link to comment https://forums.phpfreaks.com/topic/157957-solved-formatting-xml-requests/#findComment-833223 Share on other sites More sharing options...
Bifter Posted May 13, 2009 Author Share Posted May 13, 2009 Well that'll be it then - thanks for your help, everybody. Quote Link to comment https://forums.phpfreaks.com/topic/157957-solved-formatting-xml-requests/#findComment-833237 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.