travelport API以这种形式给出响应如何解析这些数据

时间:2017-07-20 11:05:20

标签: php xml-parsing

Travelport API以这种形式给出响应如何在soapxml中使用名称空间来解析这些数据。 Travelport API以此形式提供回复。如何使用名称空间从soapxml解析此数据。 ?

  <?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 个答案:

答案 0 :(得分:0)

您好,您可以使用库将xml转换为数组。下面是一个这样的库url。 http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/

它会将xml转换为以下数组格式。您可以轻松解析。

阵 (     [SOAP:Envelope] =&gt;排列         (             [SOAP:Body] =&gt;排列                 (                     [air:AvailabilitySearchRsp] =&gt;排列                         (                             [air:flightDetailsList] =&gt;排列                                 (                                     [air:flightDetails] =&gt;排列                                         (                                             [0] =&gt;排列                                                 (                                                     [@value] =&gt;                                                     [@attributes] =&gt;排列                                                         (                                                             [Key] =&gt; V7EqB14R2BKADHj4FAAAAA ==                                                             [Origin] =&gt; LGW                                                             [目的地] =&gt; EDI                                                             [DepartureTime] =&gt; 2017-07-30T19:15:00.000 + 01:00                                                             [到货时间] =&gt; 2017-07-30T20:45:00.000 + 01:00                                                             [FlightTime] =&gt; 90                                                             [TravelTime] =&gt; 90                                                             [OriginTerminal] =&gt;北航站楼                                                         )

                                            )

                                        [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
                            )

                    )

            )

    )