[英]Show cURL response in XML
我正在获取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>
这个问题是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'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.