How to read soap response xml in php

php, soap

Solution

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;

Problem

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> ```

Original source