simplexml_load_string函数不读取soap代码

时间:2014-10-19 06:02:06

标签: php soap

我有以下代码:

    $result = <<<XML
    $flight
    XML;


    $soap = simplexml_load_string($result, NULL, NULL, "http://www.travelport.com/schema/air_v25_0");
    $soap->registerXPathNamespace('air', 'http://www.travelport.com/schema/air_v25_0');
    $test = $soap->xpath('//air:lowfaresearchrsp/air:airsegmentlist/air:airsegment');

    foreach ($test as $keyO => $valueO) {
        echo "<br/>****************************************<br/>", $keyO;
        foreach ($valueO->attributes() as $key => $value) {
            echo "<br/>";
            echo $key, " - ", $value;
        }
    }

$flight是由curl_exec()函数生成的巨大肥皂串。

<?xml version="1.0" encoding="UTF-8"?>
 <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:body>
   <air:lowfaresearchrsp xmlns:air="http://www.travelport.com/schema/air_v25_0" xmlns:common_v25_0="http://www.travelport.com/schema/common_v25_0" currencytype="AUD" distanceunits="MI" responsetime="17105" transactionid="24B931EB0A0764774D967B23E7F522CB">
     <common_v25_0:responsemessage providercode="ACH" type="Error" code="700003">[ACH] Provider error: Provider transaction failed.</common_v25_0:responsemessage>
     <common_v25_0:responsemessage providercode="RCH" type="Error" code="701815">UserId,Password element(s) is/are missing in RCH Access Context.</common_v25_0:responsemessage>
     <air:flightdetailslist>
        <air:flightdetails destinationterminal="1" originterminal="2E" equipment="332" distance="3635" traveltime="520" flighttime="520" arrivaltime="2014-11-14T11:15:00.000-05:00" departuretime="2014-11-14T08:35:00.000+01:00" destination="JFK" origin="CDG" key="W57MJ5UPR3eKNycFDbvLHg==">
           <air:flightdetails destinationterminal="1" originterminal="2E" equipment="332" distance="3635" traveltime="515" flighttime="515" arrivaltime="2014-11-14T13:25:00.000-05:00" departuretime="2014-11-14T10:50:00.000+01:00" destination="JFK" origin="CDG" key="ZEprJLEGTPO5oKYbj0/8Ug==">
              <air:flightdetails destinationterminal="1" originterminal="2E" equipment="772" distance="3635" traveltime="510" flighttime="510" arrivaltime="2014-11-14T19:05:00.000-05:00" departuretime="2014-11-14T16:35:00.000+01:00" destination="JFK" origin="CDG" key="M2uITHooRlWN00a5Cf/esQ==">
                 <air:flightdetails destinationterminal="4" originterminal="2E" equipment="333" distance="3635" traveltime="510" flighttime="510" arrivaltime="2014-11-14T13:10:00.000-05:00" departuretime="2014-11-14T10:40:00.000+01:00" destination="JFK" origin="CDG" key="jl/0uOIRT3KG+qfJjfJMTQ==">
                    <air:flightdetails destinationterminal="1" originterminal="2E" equipment="388" distance="3635" traveltime="505" flighttime="505" arrivaltime="2014-11-14T16:20:00.000-05:00" departuretime="2014-11-14T13:55:00.000+01:00" destination="JFK" origin="CDG" key="LuzIXux/TmmbnuJZ9Gb23Q==">
                       <air:flightdetails destinationterminal="1" originterminal="2E" equipment="772" distance="3635" traveltime="500" flighttime="500" arrivaltime="2014-11-14T21:30:00.000-05:00" departuretime="2014-11-14T19:10:00.000+01:00" destination="JFK" origin="CDG" key="5BsjozbmT32Kw/zkkfdHJg==">
                          <air:flightdetails originterminal="2F" equipment="320" distance="247" traveltime="75" flighttime="75" arrivaltime="2014-11-14T15:40:00.000+01:00" departuretime="2014-11-14T14:25:00.000+01:00" destination="AMS" origin="CDG" key="t1PCkMniRSKw+zPsWsIjvQ==">
                             <air:flightdetails destinationterminal="4" equipment="74M" distance="3639" traveltime="595" flighttime="500" arrivaltime="2014-11-14T19:35:00.000-05:00" departuretime="2014-11-14T17:15:00.000+01:00" destination="JFK" origin="AMS" key="1r0XtTf+TvmXv64vgwAcLA==">
                                <air:flightdetails originterminal="2F" equipment="737" distance="247" traveltime="85" flighttime="85" arrivaltime="2014-11-14T11:45:00.000+01:00" departuretime="2014-11-14T10:20:00.000+01:00" destination="AMS" origin="CDG" key="cJHWqypWQ7K+EiK6gAg/uw==">
                                   <air:flightdetails destinationterminal="4" equipment="777" distance="3639" traveltime="595" flighttime="495" arrivaltime="2014-11-14T15:40:00.000-05:00" departuretime="2014-11-14T13:25:00.000+01:00" destination="JFK" origin="AMS" key="uc1ZFD5ISWG5u2vnTMl2HA==">
                                      <air:flightdetails originterminal="2F" equipment="321" distance="247" traveltime="80" flighttime="80" arrivaltime="2014-11-14T08:35:00.000+01:00" departuretime="2014-11-14T07:15:00.000+01:00" destination="AMS" origin="CDG" key="aTo+uIuHSj6gAhAgDjFPUg==">
                                         <air:flightdetails destinationterminal="4" equipment="333" distance="3639" traveltime="628" flighttime="508" arrivaltime="2014-11-14T13:03:00.000-05:00" departuretime="2014-11-14T10:35:00.000+01:00" destination="JFK" origin="AMS" key="9Nex3zh7RF6CPdrY1NhR1Q==">

...

我期待:

`**************************************** 0 availabilitysource - AvailStatusTTY optionalservicesindicator - false participantlevel - 航空公司资源 changeofplane - false 设备 - 332 eticketability - 是的 距离 - 3635 flighttime - 520 到达时间 - 2014-11-14T11:15:00.000-05:00 出发时间 - 2014-11-14T08:35:00.000 + 01:00 目的地 - 肯尼迪国际机场 起源 - CDG flightnumber - 1022 载体 - DL 组 - 0 key - GtjA5xmlS22U96KdftKeJQ ==


1 availabilitysource - AvailStatusTTY optionalservicesindicator - false participantlevel - 航空公司资源 changeofplane - false 设备 - 332 eticketability - 是的 距离 - 3635 flighttime - 515 到达时间 - 2014-11-14T13:25:00.000-05:00 出发时间 - 2014-11-14T10:50:00.000 + 01:00 目的地 - 肯尼迪国际机场 起源 - CDG flightnumber - 1023 载体 - DL 组 - 0 key - vXNcJ / 8iR / qKKO35 / 7sLoQ ==


...`

但什么也没得到。

当我在这里粘贴xml代码时

    $result = <<<XML
    $flight
    XML;

而不是$flight,它正如我预期的那样正常工作。请帮帮我!

1 个答案:

答案 0 :(得分:1)

请检查您的粘贴代码和原始代码。有时它也可能有大写字母。从firebug或任何其他编辑器复制它们时,代码会自动转换为标准类型。

我的建议是改变这个

$test = $soap->xpath('//air:lowfaresearchrsp/air:airsegmentlist/air:airsegment');

$test = $soap->xpath('//air:LowfareSearchRsp/air:AirsegmentList/air:Airsegment');