I am unable to convert SOAP response to Array in php.
here is the code
$response = $client->__doRequest($xmlRequest,$location,$action,1);
here is the SOAP response.
<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<searchflightavailability33response xmlns="http://FpwebBox.Fareportal.com/Gateway.asmx">
<searchflightavailability33result>
<Fareportal><FpSearch_AirLowFaresRS><CntKey>1777f5a7-7824-46ce-a0f8-33d5e6e96816</CntKey><Currency CurrencyCode="USD"/><OriginDestinationOptions><OutBoundOptions><OutBoundOption segmentid="9W7008V21Feb14"><FlightSegment etc....
</searchflightavailability33result>
</searchflightavailability33response>
</soap:body>
</soap:envelope>;
i used the following ways to convert to Array,but i am getting empty output.
1.echo '<pre>';print_r($client__getLastResponse());
2.echo '<pre>';print_r($response->envelope->body->searchflightavailability33response);
3.echo '<pre>';print_r($client->SearchFlightAvailability33($response));
4.simplexml_load_string($response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");
5.echo '<pre>';print_r($client->SearchFlightAvailability33($response));
please advice me.
finally i found the solution is
we can get body of the response from SOAP the following ways
example1:
example2:
I found a perfect solution to parse SOAP response to an Array :
It will give you a perfect array of SOAP XML Data.
The following SOAP response structure can be easily converted in an array using a combination of the previous methods. Using only the the function "simplexml_load_string" removing the colon ":" it returned null in some cases.
SOAP Response
PHP conversion:
Result:
Php parse SOAP response to an array
I got a single value using DOMDocument.
The second answer from @gtrujillos worked for me but with some changes, because the json string needs more formatting code in my case and the xPath needs to be in this way "//S:Body". This is the code that finally solve my problem. I toke the same SOAP Response example and the code for getting and returning a Soap response I found it here:
PHP convertion