使用jquery或javascript解析cdata中的html [英] parse html inside cdata using jquery or javascript
本文介绍了使用jquery或javascript解析cdata中的html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在获得一个看起来像这样的网站供稿
I'm getting a website feed that looks like this
<rss...>
<title> some title </title>
<content>
<![CDATA[ <div>this tag is ignored<div> who took the cookie in the cookie jar!? ]]>
</content>
</rss>
我需要将cdata的全部内容显示在html中.我正在使用jquery 1.9.1,当我使用$(xml).find('rss content').text()
获取内容部分时,
它实际上忽略了整个<div>this tag is ignored<div>
部分.有什么方法可以使用javascript或jquery在CDATA中获取所有内容?
I need the entire content of the cdata to be displayed in the html. I'm using jquery 1.9.1 and when I get the content part using $(xml).find('rss content').text()
,
it actually ignores the whole <div>this tag is ignored<div>
part. Any way to get everything inside the CDATA using javascript or jquery?
推荐答案
可能是jQuery未将您的标记解析为XML.尝试显式调用 $ .parseXML():
Chances are your markup is not parsed as XML by jQuery. Try explicitly invoking $.parseXML():
var contentText = $($.parseXML(xml)).find("rss content").text();
这篇关于使用jquery或javascript解析cdata中的html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文