2

如何从 CDATA 和描述标签中获取图像?这是 XML 代码:

<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>

这就是我得到的:

var img = $(element).find("description").text();
img = img.replace("<![CDATA[", "").replace("]]>", "");
console.log(img);
$("#img").append('<img src="' + img + '">');
4

2 回答 2

1

您是否尝试过:

var img = $(element).find("description").text();
        img = img.replace("<![CDATA[", "").replace("]]>", "");
        console.log(img);
        $("#img").append(img); // <-- use only the var ing

从描述标签中删除 CDATA 和图像标签:

var dsr = $(element).find("description").text();
dsr= dsr.substring(dsr.indexOf('>')+1, dsr.length);
于 2013-11-15T10:16:10.553 回答
0

你必须像逃跑[ and ]一样,

img = img.replace("<!\[CDATA\[", "").replace("\]\]>", "");
于 2013-11-15T10:23:55.930 回答