RSS/Atom syndication made easy


A while ago adobe released their as3syndicationlib for easy access to RSS & Atom feeds by converting either RSS 1.0/2.0 or Atom feeds into generic data accessible via the IFeed interface. These libraries also require adobe’s corelib.

It literally took me 5 minutes to write a simple wrapper class to handle the loading of the feeds, and simply trace out the headlines of each item.

[as]
package app.feeds
{
import com.adobe.xml.syndication.generic.FeedFactory;
import com.adobe.xml.syndication.generic.IFeed;
import com.adobe.xml.syndication.generic.IItem;

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class FeedLoader
{
private var loader:URLLoader;

public var feed:IFeed;

public function FeedLoader( feedURL:String )
{
loader = new URLLoader();
loader.addEventListener( Event.COMPLETE, loadComplete );
loader.load( new URLRequest( feedURL ) );
}

private function loadComplete( e:Event ):void
{
feed = FeedFactory.getFeedByXML( new XML( e.target.data ) );

var i:uint;
for( i=0; i< feed.items.length; i++ )
{
trace( IItem( feed.items[ i ] ).title );
}
}
}
}
[/as]

To implement:
[as]
var feed1:FeedLoader = new FeedLoader( ‘http://www.guardian.co.uk/rss’ );
[/as]

If you’re using flash as I am, you may find that it spits the dummy when it tries to load mx.utils.StringUtil, you’ll need to add an ActionScript classpath pointing to the flex framework, which on my machine was in “/Applications/Adobe Flex Builder 3/sdks/2.0.1/frameworks/source”

Comments are closed.