0

I would like to convert the SOAP XML response into the JSON format. Can anybody please help!

I got below SOAP XML in $response

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:awsse="http://xml.amadeus.com/2010/06/Session_v3" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soapenv:Header>
    <wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
    <wsa:From>
        <wsa:Address>https://nodeD2.test.webservices.amadeus.com/XXXXXXXX</wsa:Address>
    </wsa:From>
    <wsa:Action>http://webservices.amadeus.com/FMPTBQ_18_1_1A
    </wsa:Action>
    <wsa:MessageID>urn:uuid:a4844bc6-2e05-e8e4-b589-6f813ecad262</wsa:MessageID>
    <wsa:RelatesTo RelationshipType="http://www.w3.org/2005/08/addressing/reply">urn:uuid:ac1c8436-ecaf-4bbb-a9ff-11b466dffe18</wsa:RelatesTo>
    <awsse:Session TransactionStatusCode="End"><awsse:SessionId>00896YTRZQPQ</awsse:SessionId><awsse:SequenceNumber>1</awsse:SequenceNumber><awsse:SecurityToken>TRFTGYNBHUYKIOL</awsse:SecurityToken></awsse:Session>
</soapenv:Header>
<soapenv:Body>
    <Fare_MasterPricerTravelBoardSearchReply xmlns="http://xml.amadeus.com/FMPTBR_18_1_1A">
        <replyStatus><status><advisoryTypeInfo>FQX</advisoryTypeInfo></status></replyStatus>
        <conversionRate><conversionRateDetail><currency>USD</currency></conversionRateDetail></conversionRate>
        <familyInformation><refNumber>1</refNumber><fareFamilyname>BAGSEAT</fareFamilyname><description>OPTIMA</description><carrier>IB</carrier><services><reference>1</reference><status>CHA</status></services><services><reference>2</reference><status>CHA</status></services><services><reference>3</reference><status>INC</status></services><services><reference>4</reference><status>NOF</status></services><services><reference>5</reference><status>NOF</status></services><services><reference>6</reference><status>NOF</status></services><services><reference>7</reference><status>NOF</status></services></familyInformation>
    </Fare_MasterPricerTravelBoardSearchReply>
</soapenv:Body>
</soapenv:Envelope>

I tried this.

$xml = json_decode(json_encode(simplexml_load_string($response)), true);
print '<pre>';
print_r($xml);
print '</pre>';
  • 2
    Does this answer your question? [PHP convert XML to JSON](https://stackoverflow.com/questions/8830599/php-convert-xml-to-json) – Aksen P Dec 16 '19 at 10:12
  • shameer, please first search in the questions whether you can get the answers from that or not. otherwise it may be a duplicate question and your reputation may decrease – user6250770 Dec 16 '19 at 10:16
  • Does this answer your question? [How do you parse and process HTML/XML in PHP?](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Fabian Tjoe A On Dec 16 '19 at 11:34
  • I tried all the solution, nothing working – Sameer Ansari Dec 16 '19 at 13:14
  • @SameerAnsari what exactly doesn't work? Can you provide errors you got or comparison of actual result with expected? Be more specific, we don't have access to your environment and thoughts. – Liastre Dec 16 '19 at 18:23

1 Answers1

-1

I got the solution to the problem, working fine

$response  = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$response  = simplexml_load_string($response);
$dataArray = json_decode(json_encode((array)$response), TRUE);

echo '<pre>';print_r($dataArray);echo '</pre>';die(__FILE__.' On this line '.__LINE__);