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”

2 Comments so far

  1. Rob / October 18th, 2007 07:11

    Of course I found your tutorial AFTER spending time going through all the classes and locating/copying/pasting the Flax classes into my classpath.

    I’ve done my initial tests and I was curious if you think there is an advantage to using the IFeed interface and FeedeFactory classes, other than format independence? The brief documentation led me to believe ther might be problems if one is not specific, so I ended up doing this:

    feed = new Atom10();
    feed.parse(e.target.data);
    trace(feed.entries[0].content.value);

    Granted, this is pretty specific. Does your method of using the interfaces actually allow greater flexibility? Is it the way the developers intended us to use it?

    Thanks for your post!

  2. Ryan / January 29th, 2008 02:03

    I copied the com directories for both the as3syndicationlib and adobe’s corelib to my project’s directory. When I tried to use your class I get the error “1172: Definition mx.utils:StringUtil could not be found.” Is there something more I need to do?