如何在PHP中读取Soap Response xml

问题描述:

这是我的Soap Response xml,我需要获取RebillCustomerID 我该怎么做?

This is my Soap Response xml,I need to get RebillCustomerID How I can do this?

 <?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:Header><eWAYHeader 
   xmlns="http://www.eway.com.au/gateway/rebill/manageRebill">
    <eWAYCustomerID>87654321</eWAYCustomerID><Username>test@eway.com.au</Username>
      <Password>test123</Password></eWAYHeader></soap:Header><soap:Body>
        <CreateRebillCustomerResponse xmlns="http://www.eway.com.au/gateway/rebill/manageRebill"><CreateRebillCustomerResult>
           <Result>Success</Result><ErrorSeverity /><ErrorDetails />
      <RebillCustomerID>90246</RebillCustomerID></CreateRebillCustomerResult>                             
          </CreateRebillCustomerResponse></soap:Body></soap:Envelope><pre></pre>

尝试下面的代码.我假设您的xml响应位于$soapXMLResult变量

try the code below. I am assuming your xml response is in $soapXMLResult variable

$soap     = simplexml_load_string($soapXMLResult);
$response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children()->CreateRebillCustomerResponse;
$customerId = (string) $response->CreateRebillCustomerResult->RebillCustomerID;
echo $customerId;