无法读取 AS3 中的 RSS 数据
Trouble reading RSS data in AS3
我正在尝试在 Flash 中阅读一个简单的 RSS 提要,但一直遇到命名空间问题。从以下 rss 提要中获取内容 url 的正确方法是什么?
<rss version="2.0" xmlns:rbinl="http://reedbusiness.nl/rss/2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<item>
<media:content url="howtogetthis.jpg"/>
<title>This can be read from AS3</title>
</item>
</channel>
AS3 代码:
// this is working
xml.channel.item[0].title;
// this is not working
xml.channel.item[0].media.@url;
您需要引用 media 命名空间才能使用 url 访问 content 节点。
这是一个例子:
//get a reference to the media namespace
var ns:Namespace = new Namespace("http://search.yahoo.com/mrss/");
//use ns::content to get a reference to a `content` node in the media namespace
xml.channel.item[0].ns::content.@url;
请记住,命名空间 prefix 节点。所以节点名称是content,而不是media.
我正在尝试在 Flash 中阅读一个简单的 RSS 提要,但一直遇到命名空间问题。从以下 rss 提要中获取内容 url 的正确方法是什么?
<rss version="2.0" xmlns:rbinl="http://reedbusiness.nl/rss/2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<item>
<media:content url="howtogetthis.jpg"/>
<title>This can be read from AS3</title>
</item>
</channel>
AS3 代码:
// this is working
xml.channel.item[0].title;
// this is not working
xml.channel.item[0].media.@url;
您需要引用 media 命名空间才能使用 url 访问 content 节点。
这是一个例子:
//get a reference to the media namespace
var ns:Namespace = new Namespace("http://search.yahoo.com/mrss/");
//use ns::content to get a reference to a `content` node in the media namespace
xml.channel.item[0].ns::content.@url;
请记住,命名空间 prefix 节点。所以节点名称是content,而不是media.