从RSS CDATA解析HTML标签
问题描述:
我想问一下,如果我能解析出RSS中CDATA标签的标签吗?从RSS CDATA解析HTML标签
我使用了一个基本的jQuery函数来从RSS JSON对象,这里是我的代码:
$.get("someURL", function(data) {
console.log('InGet');
var $xml = $(data);
$xml.find("item").each(function() {
var $this = $(this),
item = {
title: $this.find("title").text(),
link: $this.find("link").text(),
description: $this.find("description").text(),
pubDate: $this.find("pubDate").text(),
author: $this.find("author").text()
}
});
});
现在我想从里面的描述中CDATA得到的HTML标签,但似乎找到()不适用于item.description。
下面是RSS
因此,一个简单的结构是什么办法像我们这些XML标签的正常方式,我可以解析CDATA?
答
只要使用jQuery。
description: $($this.find("description").text())
所以这将返回一个正常的jquery对象?描述:$($ this.find(“description”)。text())。 find(“some tag”)对我来说似乎不起作用 – user1787096
如果''包含CDATA,那么'$ this.find(“description”)。text()'将返回实际文本 - 即HTML字符串。你可以传递给jQuery来解析它。 'console.log($ this.find(“description”)。text())'输出了什么? –
Tomalak
当然你需要使用'$ xml = $ .parseXML(data)'([docs](http://api.jquery.com/jQuery.parseXML/))。我错过了那一个。 – Tomalak