2012-06-18 85 views
0

我一直在這一整天,感覺像我無處可去,我需要得到這個顯示爲一個XML,就像它是如何在這個頁面上http://admin.stock.imdfulfilment.com/api/service.asmx/GetCouriers。然而,下面的代碼PHP將XML信封解析爲XML

<? 
try 
{ 
    $soap_url = 'http://admin.stock.imdfulfilment.com/api/service.asmx?wsdl'; 
    $client = new SoapClient($soap_url, array(
       'trace' => 1, 
       'exceptions'=>true, 
       'GetCouriersResult' => 'xml') 
      ); 

    $client->GetCouriers(); 
     $xml = simplexml_load_string($client->__getLastResponse()); 
     $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); 
     $xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance'); 
    $xml->registerXPathNamespace('xsd', 'http://www.w3.org/2001/XMLSchema'); 
    foreach($xml->xpath('//soap:Envelope') as $item) { 
     echo "$item\n\n"; 
    } 
} 
catch (Exception $e) 
{ 
    print_r($e); 
} 
?> 

回答

1

它返回雙重編碼XML,我不知道爲什麼有人認爲,一個好主意(也許有人誰不希望有更新他們的WSDL打擾):

$soap_url = 'http://admin.stock.imdfulfilment.com/api/service.asmx?wsdl'; 
$client = new SoapClient($soap_url, array(
      'trace' => 1, 
      'exceptions'=>true, 
      'GetCouriersResult' => 'xml') 
     ); 

$result = $client->GetCouriers(); 
echo $result->GetCouriersResult->any; 
//or you can load it in DOM or simpleXML if you need to read it; 
$the_response_should_have_been = new simpleXMLElement($result->GetCouriersResult->any);