Reputation: 83
How do i get a image out of a CDATA and description tag? Here is the XML code:
<description>
<![CDATA[
<img src='http://www.autowereld.com/imagesDB/100/311151018460_.jpg' border='0' bordercolor='black' style='float:left; margin-right: 8px;margin-bottom: 8px;'>
]]>
Het is Subaru wat de klok slaat deze week. Na spyshots van de Subaru Legacy Touring, gelekte foto’s van de productierijpe WRX en de officiële bekendmaking van de Legacy Concept is het nu tijd voor de Crossover 7 Concept.
</description>
This is what i got:
var img = $(element).find("description").text();
img = img.replace("<![CDATA[", "").replace("]]>", "");
console.log(img);
$("#img").append('<img src="' + img + '">');
Upvotes: 2
Views: 1775
Reputation: 40639
You have to escape [ and ]
like,
img = img.replace("<!\[CDATA\[", "").replace("\]\]>", "");
Upvotes: 0
Reputation: 200
have you try to:
var img = $(element).find("description").text();
img = img.replace("<![CDATA[", "").replace("]]>", "");
console.log(img);
$("#img").append(img); // <-- use only the var ing
to remove the CDATA and image tag out of the description tag :
var dsr = $(element).find("description").text();
dsr= dsr.substring(dsr.indexOf('>')+1, dsr.length);
Upvotes: 1