使用simplexml在PHP中解析SOAP响应时遇到问题

使用simplexml在PHP中解析SOAP响应时遇到问题,php,xml,soap,Php,Xml,Soap,我正在使用cURL发布SOAP请求。答复如下: <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> <wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To> <w

我正在使用cURL发布SOAP请求。答复如下:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
  <wsa:Action>http://www.csapi.org/schema/parlayx/common/v3_1/TerminalLocationPort/getLocationForGroupResponse</wsa:Action>
</env:Header>
<env:Body>
  <ns2:getLocationForGroupResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/terminal_location/v3_1/local">
     <ns2:result>
        <address>234983</address>
        <reportStatus>Retrieved</reportStatus>
        <currentLocation>
           <latitude>12.5665</latitude>
           <longitude>43.7708</longitude>
           <timestamp>2012-01-03T17:06:16.805+01:30</timestamp>
        </currentLocation>
     </ns2:result>
     <ns2:result>
        <address>423903</address>
        <reportStatus>Retrieved</reportStatus>
        <currentLocation>
           <latitude>12.2165</latitude>
           <longitude>43.6518</longitude>
           <timestamp>2012-01-03T17:06:16.824+01:30</timestamp>
        </currentLocation>
     </ns2:result>
  </ns2:getLocationForGroupResponse>
</env:Body>
</env:Envelope>
有什么建议吗

更新: 如果服务器响应以下错误,我将如何检测它

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
      <wsa:Action>http://www.w3.org/2005/08/addressing/fault</wsa:Action>
   </env:Header>
   <env:Body>
      <env:Fault>
         <faultcode>env:Server</faultcode>
         <faultstring>Service Exception</faultstring>
         <detail>
            <ns1:ServiceException xmlns:ns1="http://www.csapi.org/schema/parlayx/common/v3_1" xmlns:ns2="http://www.csapi.org/schema/parlayx/terminal_location/v3_1/local">
               <messageId>SVC004</messageId>
               <text>Trip not Found for this MSISDN</text>
            </ns1:ServiceException>
         </detail>
      </env:Fault>
   </env:Body>
</env:Envelope>

http://www.w3.org/2005/08/addressing/anonymous
http://www.w3.org/2005/08/addressing/fault
环境:服务器
服务异常
SVC004
未找到此MSISDN的跳闸

变量名和属性名区分大小写,当我测试它时,发现还有其他东西。以下工作:

$soap = $xml->children($ns['env']);
$getaddressresponse = $soap->Body->children($ns['ns2']);
foreach ($getaddressresponse->getLocationForGroupResponse->children($ns['ns2']) as $item)
{
    $item = $item->children();
    echo $item->address . '<br />';
}

变量名和属性名是区分大小写的,当我测试它时,发现还有其他东西。以下工作:

$soap = $xml->children($ns['env']);
$getaddressresponse = $soap->Body->children($ns['ns2']);
foreach ($getaddressresponse->getLocationForGroupResponse->children($ns['ns2']) as $item)
{
    $item = $item->children();
    echo $item->address . '<br />';
}

如果您也能回答更新后的问题,我将不胜感激。谢谢。我能达到纬度/经度属性吗?明白了!echo(string)$item->currentLocation->latitude到达Body、Fault等的相同方式。获取其父节点的子节点,例如
$currentLocation=$item->currentLocation->children();echo$currentLocation->latitude希望我能放弃多个ups!再次感谢。如果您能回答更新后的问题,我将不胜感激。谢谢。我能到达纬度/经度属性吗?明白了!echo(string)$item->currentLocation->latitude到达Body、Fault等的相同方式。获取其父节点的子节点,例如
$currentLocation=$item->currentLocation->children();echo$currentLocation->latitude希望我能放弃多个ups!再次感谢。
$soap = $xml->children($ns['env']);
$getaddressresponse = $soap->Body->children($ns['ns2']);
foreach ($getaddressresponse->getLocationForGroupResponse->children($ns['ns2']) as $item)
{
    $item = $item->children();
    echo $item->address . '<br />';
}
$fault = $soap->Body->children($ns['env']);
if (isset($fault->Fault))
{
    // Handle error
}