title: Parse CDATA from a SOAP Response with PHP
body: <p>I'm trying to parse out the CDATA from a SOAP response using SimpleXML and Xpath. I get the output that I looking for but the output returned is one continuous line of data with no separators that would allow me to parse.</p>
  
  <p>I appreciate any help!</p>
  
  <p><strong>Here is the SOAP response containing the CDATA that I need to parse:</strong></p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soapenv:Body&gt;
        &lt;ns1:getIPServiceDataResponse xmlns:ns1="http://ws.icontent.idefense.com/V3/2"&gt;
           &lt;ns1:return xsi:type="ns1:IPServiceDataResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
              &lt;ns1:status&gt;Success&lt;/ns1:status&gt;
              &lt;ns1:serviceType&gt;IPservice_TIIncremental_ALL_xml_v1&lt;/ns1:serviceType&gt;
              &lt;ns1:ipserviceData&gt;&lt;![CDATA[&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;threat_indicators&gt;&lt;tidata&gt;&lt;indicator&gt;URL&lt;/indicator&gt;&lt;format&gt;STRING&lt;/format&gt;&lt;value&gt;http://update.lflink.com/aspnet_vil/debug.swf&lt;/value&gt;&lt;role&gt;EXPLOIT&lt;/role&gt;&lt;sample_md5/&gt;&lt;last_observed&gt;2012-11-02 18:13:43.587000&lt;/last_observed&gt;&lt;comment&gt;APT Blade2009 - CVE-2012-5271&lt;/comment&gt;&lt;ref_id/&gt;&lt;/tidata&gt;&lt;tidata&gt;&lt;indicator&gt;URL&lt;/indicator&gt;&lt;format&gt;STRING&lt;/format&gt;&lt;value&gt;http://update.lflink.com/crossdomain.xml&lt;/value&gt;&lt;role&gt;EXPLOIT&lt;/role&gt;&lt;sample_md5/&gt;&lt;last_observed&gt;2012-11-02 18:14:04.108000&lt;/last_observed&gt;&lt;comment&gt;APT Blade2009 - CVE-2012-5271&lt;/comment&gt;&lt;ref_id/&gt;&lt;/tidata&gt;&lt;tidata&gt;&lt;indicator&gt;DOMAIN&lt;/indicator&gt;&lt;format&gt;STRING&lt;/format&gt;&lt;value&gt;update.lflink.com&lt;/value&gt;&lt;role&gt;EXPLOIT&lt;/role&gt;&lt;sample_md5/&gt;&lt;last_observed&gt;2012-11-02 18:15:10.445000&lt;/last_observed&gt;&lt;comment&gt;APT Blade2009 - CVE-2012-5271&lt;/comment&gt;&lt;ref_id/&gt;&lt;/tidata&gt;&lt;/threat_indicators&gt;]]&gt;&lt;/ns1:ipserviceData&gt;
           &lt;/ns1:return&gt;
        &lt;/ns1:getIPServiceDataResponse&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p><strong>Here is PHP code I'm using to try to parse the CDATA:</strong></p>
  
  <pre><code>&lt;?php        
      $xml = simplexml_load_string($soap_response);
      $xml-&gt;registerXPathNamespace('ns1', 'http://ws.icontent.idefense.com/V3/2');
  
      foreach ($xml-&gt;xpath("//ns1:ipserviceData") as $item)
      {
          echo '&lt;pre&gt;';
          print_r($item);           
          echo '&lt;/pre&gt;';
      }            
  ?&gt;
  </code></pre>
  
  <p><strong>Here's the print_r output:</strong></p>
  
  <pre><code>SimpleXMLElement Object
  (
      [0] =&gt; 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
  )
  </code></pre>
  
  <p>Any ideas what I can do to make the output usable? For example, parsing out each element of the CDATA output such as: <code>&lt;indicator&gt;&lt;/indicator&gt;, &lt;value&gt;&lt;/value&gt;, &lt;role&gt;&lt;/role&gt;,</code> etc.</p>
  
  <p>FYI - Also tried using <strong>LIBXML_NOCDATA</strong> with no change in output.</p>