如何将 SOAP 响应转换为 PHP 数组? [英] How to convert SOAP response to PHP Array?

查看:34
本文介绍了如何将 SOAP 响应转换为 PHP 数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 php 中将 SOAP 响应转换为数组.

这是代码

 $response = $client->__doRequest($xmlRequest,$location,$action,1);

这是 SOAP 响应.

<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><肥皂:身体><searchflightavailability33response xmlns="http://FpwebBox.Fareportal.com/Gateway.asmx"><searchflightavailability33result>&lt;Fareportal>&lt;FpSearch_AirLowFaresRS><CntKey>1777f5a7-7824-46ce-a0f8-33d5e6e96816</CntKey&gt;CntKey&gt;CntKey&gt;"/>&lt;OriginDestinationOptions>&lt;OutBoundOptions>&lt;OutBoundOption segmentid="9W7008V21Feb14"><FlightSegment 等...</searchflightavailability33result></searchflightavailability33response></soap:body></soap:envelope>;

我使用以下方法转换为数组,但输出为空.

1.echo '

';print_r($client__getLastResponse());2.echo '

';print_r($response->envelope->body->searchflightavailability33response);3.echo '<pre>';print_r($client->SearchFlightAvailability33($response));4.simplexml_load_string($response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");5.echo '<pre>';print_r($client->SearchFlightAvailability33($response));

请给我建议.

解决方案

最后我找到了解决方案

我们可以通过以下方式从 SOAP 获取响应正文

示例 1:

$xml = new SimpleXMLElement($soapResponse);foreach($xml->xpath('//soap:body') 作为 $header) {$output = $header->registerXPathNamespace('default', 'http://FpwebBox.Fareportal.com/Gateway.asmx');}

示例 2:

$doc = new DOMDocument('1.0', 'utf-8');$doc->loadXML( $soapResponse );$XMLresults = $doc->getElementsByTagName("SearchFlightAvailability33Response");$output = $XMLresults->item(0)->nodeValue;

I am unable to convert SOAP response to Array in php.

here is the code

 $response = $client->__doRequest($xmlRequest,$location,$action,1);

here is the SOAP response.

<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<searchflightavailability33response xmlns="http://FpwebBox.Fareportal.com/Gateway.asmx">
<searchflightavailability33result>
    &lt;Fareportal&gt;&lt;FpSearch_AirLowFaresRS&gt;&lt;CntKey&gt;1777f5a7-7824-46ce-a0f8-33d5e6e96816&lt;/CntKey&gt;&lt;Currency CurrencyCode="USD"/&gt;&lt;OriginDestinationOptions&gt;&lt;OutBoundOptions&gt;&lt;OutBoundOption segmentid="9W7008V21Feb14"&gt;&lt;FlightSegment etc....
    </searchflightavailability33result>
</searchflightavailability33response>
</soap:body>
</soap:envelope>;

i used the following ways to convert to Array,but i am getting empty output.

1.echo '<pre>';print_r($client__getLastResponse());
2.echo '<pre>';print_r($response->envelope->body->searchflightavailability33response);
3.echo '<pre>';print_r($client->SearchFlightAvailability33($response));
     4.simplexml_load_string($response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");  

5.echo '<pre>';print_r($client->SearchFlightAvailability33($response));

please advice me.

解决方案

finally i found the solution is

we can get body of the response from SOAP the following ways

example1:

$xml = new SimpleXMLElement($soapResponse);
foreach($xml->xpath('//soap:body') as $header) {
    $output = $header->registerXPathNamespace('default', 'http://FpwebBox.Fareportal.com/Gateway.asmx');    
}

example2:

$doc = new DOMDocument('1.0', 'utf-8');
    $doc->loadXML( $soapResponse );
    $XMLresults     = $doc->getElementsByTagName("SearchFlightAvailability33Response");
    $output = $XMLresults->item(0)->nodeValue;

这篇关于如何将 SOAP 响应转换为 PHP 数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆