我可以直接使用jQuery读取XML Feed,但是当我使用'console.log'显示返回XML文档时,'description'标签只显示'#cdata-section'在控制台中,但是当我将它们放入HTML时,它能够显示完整的内容。输出是一篇文章的完整内容,如下面的“示例内容”。通过jQuery读取XML(读取变量)
样本含量:
<p> line 1 line 1 line 1</p>
<p> line 2 line 2 line 2</p>
<img src='..' />
<p> ... ... </p>
现在,如果我使用jQuery经由阿贾克斯检索它,我将使用一个“降序”变量来保存这个“描述”节点(其保持上述样品含量) ,但是我如何阅读这个'desc'变量中的'p'或'img'元素?
我想获得这个'desc'变量里面的元素,我的目标是读取img标签。有没有办法做到这一点?注意:在放入HTML之前。
XML:
<channel>
<title>Property</title>
<link></link>
<lastbuilddate>Wed, 13 Oct 2010 23:50:51 GMT</lastbuilddate>
<generator>FeedCreator 1.8.0-dev ([email protected])</generator>
<atom:link href="sample.com" rel="self" type="application/rss+xml"></atom:link>
<item>
<title>sample title</title>
<description>
#cdata-section
</description>
<pubdate>Wed, 08 Dec 2010 23:04:25 GMT</pubdate>
</item>
<channel>
的jQuery:
$.ajax({
type: "GET",
url: "http://feed6.xml",
dataType: "xml",
success: function(xml) {
console.log(xml);
$(xml).find('channel').each(function(){
$(this).find('item').each(function(){
var desc = $(this).find('description').text();
console.log(desc);
});
});
}
});
@arkchong您是否试过这段代码? – Vivek 2010-12-10 05:10:09