简体   繁体   中英

Read SOAP response xml using php, is cannot read xml file

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP:Body>
        <air:LowFareSearchRsp TransactionId="6F965E450A076478B86F876C892DCB3B" ResponseTime="42833" DistanceUnits="MI" CurrencyType="LKR" xmlns:air="http://www.travelport.com/schema/air_v25_0" xmlns:common_v25_0="http://www.travelport.com/schema/common_v25_0">
            <common_v25_0:ResponseMessage Code="2027" Type="Warning" ProviderCode="1P">Requested date is out of provider supported date range. Results may have been returned with other dates.</common_v25_0:ResponseMessage>
            <air:FlightDetailsList>
                <air:FlightDetails Key="/f+YonrXRQKE6/ePot1icg==" Origin="CMB" Destination="BKK" DepartureTime="2015-11-14T01:40:00.000+05:30" ArrivalTime="2015-11-14T06:35:00.000+07:00" FlightTime="205" TravelTime="205" Distance="1485" Equipment="320"/>
                <air:FlightDetails Key="RZaPXzrqT7aBia5Rv5HDSw==" Origin="CMB" Destination="BKK" DepartureTime="2015-11-14T07:20:00.000+05:30" ArrivalTime="2015-11-14T12:15:00.000+07:00" FlightTime="205" TravelTime="205" Distance="1485" Equipment="332"/>
                <air:FlightDetails Key="jZVn/oAjTOGbbPrq7V0WXQ==" Origin="CMB" Destination="KUL" DepartureTime="2015-11-14T00:40:00.000+05:30" ArrivalTime="2015-11-14T06:55:00.000+08:00" FlightTime="225" TravelTime="225" Distance="1530" Equipment="320" DestinationTerminal="M"/>
                <air:FlightDetails Key="47Vb5TYpQpGruHS0FlMuEA==" Origin="KUL" Destination="BKK" DepartureTime="2015-11-14T13:05:00.000+08:00" ArrivalTime="2015-11-14T14:10:00.000+07:00" FlightTime="125" TravelTime="495" Distance="759" Equipment="787" OriginTerminal="M"/>
                <air:FlightDetails Key="S4cPtkw/TiWUazgonAmzrw==" Origin="CMB" Destination="KUL" DepartureTime="2015-11-14T07:30:00.000+05:30" ArrivalTime="2015-11-14T13:45:00.000+08:00" FlightTime="225" TravelTime="225" Distance="1530" Equipment="321" DestinationTerminal="M"/>
                <air:FlightDetails Key="5hrw3GrAQ929uDyp8ROe7A==" Origin="KUL" Destination="BKK" DepartureTime="2015-11-14T21:00:00.000+08:00" ArrivalTime="2015-11-14T22:05:00.000+07:00" FlightTime="125" TravelTime="560" Distance="759" Equipment="787" OriginTerminal="M"/>
                <air:FlightDetails Key="9W5gjL57STePdYm7f6DPIA==" Origin="KUL" Destination="BKK" DepartureTime="2015-11-14T15:15:00.000+08:00" ArrivalTime=

How can I read this file with php? I tried to read it SimpleXMLElement but it does not read file and give empty object

How did you try to read the xml? Did you may forgot to register your xpath Namespace?

Here is an example, being $yourSoapResponse the string response of your request:

$xml = new SimpleXMLElement($yourSoapResponse); 
$xml->registerXPathNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
$body = $xml->xpath("//soap:Body");
print_r($body); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM