搜尋

首頁  >  問答  >  主體

php7 - php 解析SOAP的xml失敗

$xmlStr = <<<xml
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <client_insetResponse xmlns="http://120.26.103.193:2017/webservices/">
            <client_insetResult>0|</client_insetResult>
        </client_insetResponse>
    </soap:Body>
</soap:Envelope>
xml;
$xmlObj = simplexml_load_string($xmlStr);
var_dump($xmlObj);

上面程式碼列印結果為空對象,說明解析失敗

ringa_leeringa_lee2755 天前2752

全部回覆(2)我來回復

  • 某草草

    某草草2017-05-16 13:16:49

    不能辨識xmlns:soap,xmlns:xsi,xmlns:xsd

    可以把xmlns:soap改为xmlns-soap再處理。

    回覆
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 13:16:49

    soap的命名空間不被識別,參考下面代碼:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Body>
            <client_insetResponse xmlns="http://127.0.0.1/webservices/">
                <client_insetResult>0|</client_insetResult>
            </client_insetResponse>
        </soap:Body>
    </soap:Envelope>
    xml;
        
    $xmlObj = simplexml_load_string($xmlStr);
    $xmlObj->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
    $result = $xmlObj->xpath("soap:Body");
    
    print_r($result);

    回覆
    0
  • 取消回覆