繁体   English   中英

如何将Saber SOAP API响应转换为PHP数组

[英]How to convert Sabre SOAP API response to PHP array

我收到Saber SOAP API响应,例如:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:header></soap-env:header>
    <soap-env:body>
    <ota_airlowfaresearchrs xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1.0" priceditincount="50" brandedonewayitincount="0" simpleonewayitincount="0" departeditincount="0" soldoutitincount="0" availableitincount="0">
    <success>
    <priceditineraries><priceditinerary sequencenumber="1"></priceditinerary>
    <priceditinerary sequencenumber="2"></priceditinerary></priceditineraries>
    </success>
    </ota_airlowfaresearchrs>
    </soap-env:body>
</soap-env:envelope>

但是,当我尝试使用simplexml_load_string时,遇到了将其转换为PHP数组的问题。 我尝试的是:

$parser = simplexml_load_string($res);  
$parserEnv = $parser->children('soap-env', true);
$response = $parserEnv->body->ota_airlowfaresearchrs;

其返回空数组如: SimpleXMLElement Object ( )

$parser = simplexml_load_string($res); 

您必须进行如下更改:

$parser = simplexml_load_string($res, "SimpleXMLElement", LIBXML_NOCDATA);

LIBXML_NOCDATA :您可以使用此函数调用来使simplexml将CDATA转换为纯文本。

作为参考: 将SOAP XML响应转换为PHP对象或数组

我通过以下方法得到了答案:

$soap     = simplexml_load_string($res);
$response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')
                 ->body->children()
                 ->ota_airlowfaresearchrs
                 ->success
                 ->priceditineraries

谢谢@lalithkumar

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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