我試圖使用SimpleXML和Xpath從SOAP響應中解析出CDATA。我得到我想要的輸出,但返回的輸出是一個連續的數據行,沒有可以讓我解析的分隔符。使用PHP從SOAP響應中解析CDATA
我感謝任何幫助!
下面是一個包含我需要解析CDATA SOAP響應:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:getIPServiceDataResponse xmlns:ns1="http://ws.icontent.idefense.com/V3/2">
<ns1:return xsi:type="ns1:IPServiceDataResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:status>Success</ns1:status>
<ns1:serviceType>IPservice_TIIncremental_ALL_xml_v1</ns1:serviceType>
<ns1:ipserviceData><![CDATA[<?xml version="1.0" encoding="utf-8"?><threat_indicators><tidata><indicator>URL</indicator><format>STRING</format><value>http://update.lflink.com/aspnet_vil/debug.swf</value><role>EXPLOIT</role><sample_md5/><last_observed>2012-11-02 18:13:43.587000</last_observed><comment>APT Blade2009 - CVE-2012-5271</comment><ref_id/></tidata><tidata><indicator>URL</indicator><format>STRING</format><value>http://update.lflink.com/crossdomain.xml</value><role>EXPLOIT</role><sample_md5/><last_observed>2012-11-02 18:14:04.108000</last_observed><comment>APT Blade2009 - CVE-2012-5271</comment><ref_id/></tidata><tidata><indicator>DOMAIN</indicator><format>STRING</format><value>update.lflink.com</value><role>EXPLOIT</role><sample_md5/><last_observed>2012-11-02 18:15:10.445000</last_observed><comment>APT Blade2009 - CVE-2012-5271</comment><ref_id/></tidata></threat_indicators>]]></ns1:ipserviceData>
</ns1:return>
</ns1:getIPServiceDataResponse>
</soapenv:Body>
</soapenv:Envelope>
這裏是我使用的嘗試解析CDATA PHP代碼:
<?php
$xml = simplexml_load_string($soap_response);
$xml->registerXPathNamespace('ns1', 'http://ws.icontent.idefense.com/V3/2');
foreach ($xml->xpath("//ns1:ipserviceData") as $item)
{
echo '<pre>';
print_r($item);
echo '</pre>';
}
?>
以下是print_r輸出:
SimpleXMLElement Object
(
[0] => URLSTRINGhttp://update.lflink.com/aspnet_vil/debug.swfEXPLOIT2012-11-02 18:13:43.587000APT Blade2009 - CVE-2012-5271URLSTRINGhttp://update.lflink.com/crossdomain.xmlEXPLOIT2012-11-02 18:14:04.108000APT Blade2009 - CVE-2012-5271DOMAINSTRINGupdate.lflink.comEXPLOIT2012-11-02 18:15:10.445000APT Blade2009 - CVE-2012-5271
)
任何想法,我可以做什麼,使輸出可用?例如,CDATA輸出的每個元素解析出如:<indicator></indicator>, <value></value>, <role></role>,
等
FYI - 使用LIBXML_NOCDATA與輸出沒有變化也試過。
檢查下面的網址。它適用於我 [https://stackoverflow.com/a/21330977/1248953](https://stackoverflow.com/a/21330977/1248953) –