tags:

views:

185

answers:

2

Hi,

I am extracting data from an XML and some tags have data inside CDATA in this way

<description><![CDATA[Changes (as compared to 8.17) include:
Features:
    * Added a &#8216;Schema Optimizer&#8217; feature. Based on &#8220;procedure analyse()&#8221; it will propose alterations to data types for a table based on analysis on what data are stored in the table. The feature is available from INFO tab/HTML mode.  Refer to documentation for details.
    * A table can now be added [...]]]>
</description>

I am already using preq_match to extract data from description tag.So How can I extract data from CDATA?

+7  A: 

Regardless of the language, don't use regular expressions to parse XML - you will almost certainly get it wrong. Use an XML parser.

Pavel Minaev
A: 

you should use simple_xml and xpath if you need to extract a complex set of data.

<?php
$string = <<<XML
<?xml version='1.0'?> 
<document>
 <title>Forty What?</title>
 <from>Joe</from>
 <to>Jane</to>
 <body>
  I know that's the answer -- but what's the question?
 </body>
</document>
XML;

$xml = simplexml_load_string($string);

var_dump($xml);
?>

would provide output like this :

SimpleXMLElement Object
(
  [title] => Forty What?
  [from] => Joe
  [to] => Jane
  [body] =>
   I know that's the answer -- but what's the question?
)

so in your case you would just to navigate inside your document really more easy then reg expressions, isn't it?

RageZ