2016-04-27 30 views
1

我想用PHP解析下面的SOAP。我已經嘗試了在這裏找到的每個可能的解決方案,但由於使用的命名空間,我沒有管理它。可以請別人幫忙嗎?使用php解析名稱空間的SOAP

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:geo="http://path.to.geo" xmlns:geo1="http://path/"> 
<soapenv:Header/> 
<soapenv:Body> 
    <geo:SendClient> 
    <geo1:SendClientRequest> 
     <geo1:GeneralInfo> 
      <geo1:Team>AP</geo1:Team> 
     </geo1:GeneralInfo> 
    </geo1:SendClientRequest> 
    </geo:SendClient> 
</soapenv:Body> 
</soapenv:Envelope> 

我想在輸出中獲取AP值。

$xmlData = simplexml_load_file('request.xml'); 
$xmlData->registerXPathNamespace('geo1', 'http://path/'); 
foreach ($xmlData->xpath('//geo1:GeneralInfo') as $item) 
{ 
    print_r($item); 
var_export($item->xpath('//geo1:Team')); 
} 

回答

0

花費數小時後,我發現,打印輸出正確的方法是:

$result = $item->xpath('//geo1:Team'); 
echo (string)$result[0]; 

,而不是

var_export($item->xpath('//geo1:Team'));