Bifter Posted May 14, 2009 Share Posted May 14, 2009 Hi, Im using the following to process an XML request from an ADSL provider: <?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.xxxxx.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">xxxxxx</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; $xml = simplexml_load_string($Response); echo "<pre>"; var_dump($xml); echo "</pre>"; ?> This returns the following in the browser (I have cut this down as it is alot of information): object(SimpleXMLElement)#1 (3) { ["@attributes"]=> array(1) { ["id"]=> string(32) "8c4566926694d7227d9d73fd8c2acc5b" } ["block"]=> array(3) { [0]=> object(SimpleXMLElement)#2 (3) { ["@attributes"]=> array(1) { ["name"]=> string(12) "availability" } ["a"]=> array(2) { [0]=> string(1) "5" [1]=> string(7) "LU2 0JJ" } ["block"]=> array(3) { [0]=> object(SimpleXMLElement)#6 (2) { ["@attributes"]=> array(1) { ["name"]=> string(21) "classic-qualification" } ["a"]=> array(4) { [0]=> string(1) "Z" [1]=> string(1) "G" [2]=> string(7) "2097152" [3]=> string(1) "G" } } [1]=> object(SimpleXMLElement)#7 (2) { ["@attributes"]=> array(1) { ["name"]=> string( "exchange" } ["a"]=> array(4) { [0]=> string(4) "SMLT" [1]=> string(5) "LUTON" [2]=> string(1) "E" [3]=> string(1) "Y" } } The equivilant raw XML looks like this: <?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> The problem im having is selecting certain values in the array and using them as variables. Would be greatful for any surgestions. Thanks, B. Link to comment https://forums.phpfreaks.com/topic/158099-php-with-xml-requests/ Share on other sites More sharing options...
Bifter Posted May 14, 2009 Author Share Posted May 14, 2009 Am I not explaining myself clearly or is it an impossible question? :-\ Link to comment https://forums.phpfreaks.com/topic/158099-php-with-xml-requests/#findComment-834232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.