2016-07-26 89 views
0

我越來越低於SOAP API響應並試圖讀取XML節點值,但未獲取resultcode & message值。PHP - 無法讀取XML節點值

$result = '<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <tic:reservationresponse xmlns:tic="http://example.com/"> 
      <tic:reservationresp> 
       <tic:resultcode>-204</tic:resultcode> 
       <tic:message>Invalid Location Id</tic:message> 
      </tic:reservationresp> 
     </tic:reservationresponse> 
    </soap:body> 
</soapenv:envelope>'; 

$xml  = simplexml_load_string($result); 
$soapenv = $xml->children("http://schemas.xmlsoap.org/soap/envelope/"); 
$tns  = $soapenv->Body->children("http://example.com/"); 

echo $tns->reservationresponse->reservationresp->resultcode; 

我做錯了什麼。任何想法。

謝謝。

回答

0

您可能會踢自己,但標籤名稱區分大小寫。你只需要改變

$tns = $soapenv->Body->children("http://example.com/"); 

到:

$tns = $soapenv->body->children("http://example.com/");