1

任何人都可以帮助我解析肥皂响应。我尝试了很多很多方法,但这对我没有帮助。我卡住了。有回应:

  <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:body>
    <ns2:findflightresponse xmlns:ns2="http://cxf.apache.org">
      <return>
        <clstobook>K</clstobook>
        <flightsegment>
          <arrivalairport>
            <locationcode>LHR</locationcode>
            <terminal>1</terminal>
          </arrivalairport>
          <arrivaldatetime>2013-09-01T16:15:00</arrivaldatetime>
          <bookingclassavaillist>
            <resbookdesigcode>W</resbookdesigcode>
            <resbookdesigquantity>0</resbookdesigquantity>
            <resbookdesigstatuscode>3</resbookdesigstatuscode>
            <rph>1</rph>
          </bookingclassavaillist>
          <bookingclassavaillist>
            <resbookdesigcode>U</resbookdesigcode>
            <resbookdesigquantity>0</resbookdesigquantity>
            <resbookdesigstatuscode>2</resbookdesigstatuscode>
            <rph>1</rph>
          </bookingclassavaillist>
          <departureairport>
            <locationcode>VKO</locationcode>
          </departureairport>
          <departuredatetime>2013-09-01T15:10:00</departuredatetime>
          <equipment>
            <airequiptype>738</airequiptype>
          </equipment>
          <flightnumber>353</flightnumber>
          <marketingairline>
            <code>UN</code>
          </marketingairline>
          <marketingcabin>
            <meal>B</meal>
          </marketingcabin>
          <rph>1</rph>
          <stopquantity>0</stopquantity>
        </flightsegment>
        <lateforsale>false</lateforsale>
        <noseats>false</noseats>
      </return>
    </ns2:findflightresponse>
  </soap:body>
</soap:envelope>

我试过像:

$xml_response = $ch_result;
$xml = simplexml_load_string($xml_response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('ns2', 'http://cxf.apache.org');
print_r($xml);

但是,它返回:

SimpleXMLElement Object ( [Body] => SimpleXMLElement Object ( ) ) 

我从不使用 xml 文件。那是我第一次练习 xml soap,我没有很多知识。有谁能够帮我?

4

1 回答 1

0

你可以这样试试:

        $xml = str_replace("soap:", "", $xml);
        $xml = str_replace("ns2:", "", $xml);
        $xml = str_replace("ns3:", "", $xml);
        $xml = str_replace("&#0", "", $xml);

        $array = xml2array($xml);
        $array = $array['envelope']['body']['findflightresponse'];

        print_r($array, true);

希望它会帮助你。

于 2013-09-01T08:11:59.480 回答