I have no issue importing the content inside "article" using : //description/div[@id="article"]

<description>
        <div id="article">Testing</a></div>
 </description>

But I'm unable to retrieve the content if CDATA is around

<description>
<![CDATA[
        <div id="article">Testing</a></div>
]]>
 </description>

Any idea?

Thanks!

Comments

emptyvoid’s picture

I believe this is by design. The CDATA wrapper tells the parser to not validate the content within it. It is treated as "RAW" content. This could include binary content hex coded, or rather hackish HTML, XML, SGML, anything really. So if you want to "parse" the content within the CDATA node I would suggest extracting the contents then run it through another instance of the parser.

Magicthought’s picture

how do you do that with xpath parser?

I can extract all the CDATA content with a query, is there a way to run a query over that result?

I've tried using the $temp provided variable but no luck; any tips?

ndobromirov’s picture

This can be done with the removal of the CDATA from the raw HTML data before parsing, but it is not safe.

Attaching a simple patch, that solves the issue.

It is an option to add a configuration checkbox that enables the new behavior (default value will be unchecked) in the parser settings page.

twistor’s picture

Status: Active » Closed (works as designed)

This is definitely by design. We cannot, and will not be able to parse inside CDATA.
See #1459870: Add XPath query Feeds Tamper plugin. for an alternative.

ndobromirov’s picture

In a more generic way, there could be added a hook before the parsing.
It will be able to alter the raw data that will go into the parser.
For example it could apply an XSLT, but this is probably for a separate issue.