【问题标题】:PHP Parse SOAP envelope to XMLPHP 将 SOAP 信封解析为 XML
【发布时间】:2012-06-18 21:13:10
【问题描述】:

我整天都在做这个,感觉我无处可去,我需要让它显示为一个 xml,就像它在这个页面上的样子 http://admin.stock.imdfulfilment.com/api/service.asmx/GetCouriers。然而下面的代码

<?
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);
}
?>

【问题讨论】:

    标签: php soap xml-parsing


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 2020-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多