xml内容是:
<?xml version="1.0"?>
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Some Title.</title>
<description>Pipes Output</description>
<link>http://pipes.yahoo.com/pipes/pipe.info</link>
<atom:link rel="next" href="http://pipes.yahoo.com/pipes/pipe.run"/>
<pubDate>Fri, 17 Aug 2012 07:25:28 +0000</pubDate>
<generator>http://pipes.yahoo.com/pipes</generator>
<item>
<title>Title 1</title>
<link>http://feedproxy.google.com</link>
<description>there is no description for this</description>
<guid isPermaLink="false">http://wordpress.com</guid>
<pubDate>Thu, 16 Aug 2012 16:47:41 +0000</pubDate>
<media:content medium="image" url="">
<media:title type="html">some media</media:title>
</media:content>
<media:content medium="image" url="">
<media:title type="html">Image</media:title>
</media:content>
<media:content medium="image" url="">
<media:title type="html">Image</media:title>
</media:content>
<media:content medium="image" url="">
<media:title type="html">Image</media:title>
</media:content>
<category>News</category>
</item>
<item>
<title>title 3</title>
<link>http://google.com</link>
<description>some description</description>
<author>Self</author>
<guid isPermaLink="false"></guid>
<pubDate>Wed, 15 Aug 2012 17:43:32 +0000</pubDate>
<enclosure type=""/>
</item>
</channel>
</rss>
正如所观察到的,有些项目有<media:content>
元素,有些没有
Jquery解析xml如下:
function loadNews()
{
var entries = [];
var selectedEntry = "";
$loadMore = $('#btn_loadmore');
$loadMore.hide();
var RSS = "news.xml";
//$.get(RSS, {}, function(res, code) {
$.ajax(
{
type: "POST",
url: "news.xml",
dataType: "xml",
async: false,
success: function(res){
var xml = $(res);
var items = xml.find("item");
$.each(items, function(i, v) {
entry = {
title:$(v).find("\\:title, title").text(),
link:$(v).find("link").text().replace(/\/+$/, ""),
description:$.trim($(v).find("description").text())
};
entries.push(entry);
});
var s = '';
for(i=0;i<10;i++)
{
console.log(i + "--------------------------");
if(i>=entries.length)
break;
alert(entries[i].title);
console.log(entries[i].description);
console.log(entries[i].link);
}
}
});
}
问题:
在 Firefox 中,上面的代码工作正常。然而,在 Safari 中,媒体标签内的文本也会附加在标题中
Firefox 中的输出:Title 1
Safari 中的输出:Title 1some mediaImageImageImage
编辑:我如何告诉选择器不要选择<media:title>
但只<title>
我确实通过了这篇文章,但没有任何帮助。
我错过了什么?
*我正在使用jquery 1.7.1,问题与 jquery 1.6.**** 相同。