10月 16, 2009 0
[as3]parsing rss feeds
○as3syndicationlib
rssフィードをパースしてくれるライブラリ。
RSS1.0、RSS2.0、ATOM1.0など対応。
http://code.google.com/p/as3syndicationlib/
簡単なサンプル作成しました。
<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できるからいいです。