travelport API giving response in this form how to parse this data

267 views Asked by At

Travelport API giving response in this form how to parse this data from soapxml as it is using namespaces. Travelport API giving response in this form. How to parse this data from soapxml as it is using namespaces. ?

  <?xml version="1.0"?>
  <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP:Body>
<air:AvailabilitySearchRsp 
xmlns:air="http://www.travelport.com/schema/air_v29_0" 
xmlns:common_v29_0="http://www.travelport.com/schema/common_v29_0" 
TraceId="trace" TransactionId="5EF374190A076478623DB8BB3DCEE30E" 
ResponseTime="801" DistanceUnits="MI">
<air:FlightDetailsList>
  <air:FlightDetails Key="V7EqB14R2BKADHj4FAAAAA==" Origin="LGW" 
   Destination="EDI" DepartureTime="2017-07-30T19:15:00.000+01:00" 
   ArrivalTime="2017-07-30T20:45:00.000+01:00" FlightTime="90" 
   TravelTime="90" OriginTerminal="North Terminal"/>
   <air:FlightDetails Key="V7EqB14R2BKAGHj4FAAAAA==" Origin="LGW" 
   Destination="EDI" DepartureTime="2017-07-30T20:55:00.000+01:00"  
   ArrivalTime="2017-07-30T22:25:00.000+01:00" FlightTime="90" 
   TravelTime="90" OriginTerminal="North Terminal"/>
   <air:FlightDetails Key="V7EqB14R2BKAJHj4FAAAAA==" Origin="LGW" 
    Destination="EDI" DepartureTime="2017-07-30T13:35:00.000+01:00" 
    ArrivalTime="2017-07-30T15:10:00.000+01:00" FlightTime="95" 
    TravelTime="95" OriginTerminal="North Terminal"/>
    <air:FlightDetails Key="V7EqB14R2BKAMHj4FAAAAA==" Origin="LGW" 
    Destination="EDI" DepartureTime="2017-07-30T15:50:00.000+01:00" 
    ArrivalTime="2017-07-30T17:25:00.000+01:00" FlightTime="95" 
    TravelTime="95" OriginTerminal="North Terminal"/>
  </air:FlightDetailsList>
 </air:AvailabilitySearchRsp>
</SOAP:Body>
</SOAP:Envelope>
1

There are 1 answers

0
Himani On

Hi you can use library to convert xml to array. Below is one such library url. http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/

It'll convert you xml to below array format. Which you can parse easily.

Array ( [SOAP:Envelope] => Array ( [SOAP:Body] => Array ( [air:AvailabilitySearchRsp] => Array ( [air:FlightDetailsList] => Array ( [air:FlightDetails] => Array ( [0] => Array ( [@value] => [@attributes] => Array ( [Key] => V7EqB14R2BKADHj4FAAAAA== [Origin] => LGW [Destination] => EDI [DepartureTime] => 2017-07-30T19:15:00.000+01:00 [ArrivalTime] => 2017-07-30T20:45:00.000+01:00 [FlightTime] => 90 [TravelTime] => 90 [OriginTerminal] => North Terminal )

                                            )

                                        [1] => Array
                                            (
                                                [@value] => 
                                                [@attributes] => Array
                                                    (
                                                        [Key] => V7EqB14R2BKAGHj4FAAAAA==
                                                        [Origin] => LGW
                                                        [Destination] => EDI
                                                        [DepartureTime] => 2017-07-30T20:55:00.000+01:00
                                                        [ArrivalTime] => 2017-07-30T22:25:00.000+01:00
                                                        [FlightTime] => 90
                                                        [TravelTime] => 90
                                                        [OriginTerminal] => North Terminal
                                                    )

                                            )

                                        [2] => Array
                                            (
                                                [@value] => 
                                                [@attributes] => Array
                                                    (
                                                        [Key] => V7EqB14R2BKAJHj4FAAAAA==
                                                        [Origin] => LGW
                                                        [Destination] => EDI
                                                        [DepartureTime] => 2017-07-30T13:35:00.000+01:00
                                                        [ArrivalTime] => 2017-07-30T15:10:00.000+01:00
                                                        [FlightTime] => 95
                                                        [TravelTime] => 95
                                                        [OriginTerminal] => North Terminal
                                                    )

                                            )

                                        [3] => Array
                                            (
                                                [@value] => 
                                                [@attributes] => Array
                                                    (
                                                        [Key] => V7EqB14R2BKAMHj4FAAAAA==
                                                        [Origin] => LGW
                                                        [Destination] => EDI
                                                        [DepartureTime] => 2017-07-30T15:50:00.000+01:00
                                                        [ArrivalTime] => 2017-07-30T17:25:00.000+01:00
                                                        [FlightTime] => 95
                                                        [TravelTime] => 95
                                                        [OriginTerminal] => North Terminal
                                                    )

                                            )

                                    )

                            )

                        [@attributes] => Array
                            (
                                [TraceId] => trace
                                [TransactionId] => 5EF374190A076478623DB8BB3DCEE30E
                                [ResponseTime] => 801
                                [DistanceUnits] => MI
                            )

                    )

            )

    )

)