Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP将SOAP信封解析为XML_Php_Soap_Xml Parsing - Fatal编程技术网

PHP将SOAP信封解析为XML

PHP将SOAP信封解析为XML,php,soap,xml-parsing,Php,Soap,Xml Parsing,我整天都在这样做,感觉自己一事无成,我需要让它以xml的形式显示出来,就像它在这个页面上一样。但是下面的代码 <? try { $soap_url = 'http://admin.stock.imdfulfilment.com/api/service.asmx?wsdl'; $client = new SoapClient($soap_url, array( 'trace' => 1, 'exceptio

我整天都在这样做,感觉自己一事无成,我需要让它以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);
}
?>
GetCouriers();
$xml=simplexml\u load\u string($client->\u 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')作为$item){
回显“$item\n\n”;
}
}
捕获(例外$e)
{
印刷品(港币);;
}
?>

它返回双重编码的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);