我收到SOAP API的响应,响应有标题,正文,状态等。我想从响应中获取状态。虽然响应是xml格式,但当我回显响应时,它显示在没有xml标记的一行上。 当我在下面使用时,它以xml格式显示:
echo '<pre>';
echo htmlspecialchars(print_r($response, true));
echo '</pre>';
现在我想从这个xml获取状态。 我这样做,但没有得到任何东西
$oXML = new SimpleXMLElement($response);
foreach($oXML as $oEntry){
echo $oEntry->status . "\n";echo "in foreach";
if ($oEntry->status == "Failure"){echo "Failed";}
else echo "success";
}
同样如此
$xml = simplexml_load_string($response);
print_r($xml);
如何获得状态?状态为“成功”或“失败”
xml响应是:
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope....>
<soapenv:Header>
.
.
.
</soapenv:Header>
<soapenv:Body>
<ns2:addOrganisationResponse ....>
.
.
.
<ns1:status>Success</ns1:status>
</ns2:addOrganisationResponse>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:0)
这个问题在6个月前被问过,但也许这个答案对某些人有帮助。
$response = curl_exec($soap_do);
$header_size = curl_getinfo($soap_do,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr($response, $header_size);
$xmlStr = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $result['body']);
$resultXml = new SimpleXMLElement($xmlStr);
$xmlArray = (json_decode(json_encode($resultXml),true));
$status = $xmlArray ['soapenvBody']['ns2addOrganisationResponse']['ns1status'];