MAX Factory

Icon

モバイル(フィーチャーフォン、スマートフォン、タブレット)を中心とした技術メモ

[as3]parsing rss feeds

○as3syndicationlib
rssフィードをパースしてくれるライブラリ。
RSS1.0、RSS2.0、ATOM1.0など対応。
http://code.google.com/p/as3syndicationlib/

簡単なサンプル作成しました。

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application
xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute” initialize=”init();”>

<mx:Script>
<![CDATA[
import com.adobe.xml.syndication.generic.IItem;
import com.adobe.xml.syndication.generic.IFeed;
import com.adobe.xml.syndication.generic.FeedFactory;

private function init():void
{
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://maxfactory.biz/blog/feed/");

loader.addEventListener(Event.COMPLETE, loadCompleteHandler);
loader.load( request );
}

private function loadCompleteHandler(e:Event):void
{
var rssString:String = URLLoader(e.target).data;
var feed:IFeed = FeedFactory.getFeedByString(rssString);
for (var i:uint=0; i<feed.items.length; i++)
{
var item:IItem = feed.items[i] as IItem;
trace( “title = ” + item.title );    //タイトル
trace( “link = ” + item.link );        //リンク
trace( “date = ” + item.date );        //日付
trace( “excerpt.value = ” + item.excerpt.value );    //記事内容(抜粋)
}
}
]]>
</mx:Script>

</mx:Application>

サンプルでは、このブログのRSS Feedを読み込んで、
記事のタイトル、日付などの情報をtraceしてます。
Feedのtype(RSS1.0、RSS2.0、ATOM1.0)を意識しないで、parseできるからいいです。

Category: as3, flex component, flex入門

Tagged: ,

 

2009年10月
« 9月   11月 »
 1234
567891011
12131415161718
19202122232425
262728293031