2016-07-26 74 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/");