我正在获得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;
其返回的emptry数组如:SimpleXMLElement Object ( )
答案 0 :(得分:0)
这
$parser = simplexml_load_string($res);
你必须改变如下:
$parser = simplexml_load_string($res, "SimpleXMLElement", LIBXML_NOCDATA);
LIBXML_NOCDATA :您可以使用此函数调用将simplexml转换为纯文本。
答案 1 :(得分:0)
作为参考:converting SOAP XML response to a PHP object or array
我通过以下方式得到答案:
$soap = simplexml_load_string($res);
$response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')
->body->children()
->ota_airlowfaresearchrs
->success
->priceditineraries
以任何方式感谢@lalithkumar