jump to navigation

Parsing RSS 2.0 Feeds in ActionScript 3 October 14, 2010

Posted by Tournas Dimitrios in Actionscript.

One of the ActionScript libraries that you my find useful is the  as3syndicationlib. This is an opensource library originally developed by Christian Cantrell, and open sourced by Adobe. The library provides code for parsing RSS 1.0, RSS 2.0 and ATOM data feeds. It also provides a generic interface for parsing feeds when you do not know the format of the feeds.

Below is a simple example of how to use the library to parse an RSS 2.0 feed. The example is written in Flex 3 and ActionScript 3, the code is  separated , that  makes it easy to also use it within Flash CS3. Caution : works the same as loading any other remote data vs all crossdomain and security restrictions apply. So the remote site must have the crossdomain.xml with the appropriate privileges enabled , otherwise you must implement a proxy solution like PHP and MagpieRSS . See also Using a PHP Proxy with Flex to talk Cross Domain .

In order to compile and run the code below, you need to download the SWC (or source code) for the as3syndicationlib and corelib libraries (as3syndicationlib requires corelib to compile).


<!--?xml version="1.0" encoding="utf-8"?-->
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

	<mx:Script source="RSSExampleClass.as" />

	<mx:<span class="hiddenSpellError" pre="">TextArea left="20" top="10" bottom="40" right="10" id="outputField"/>
	<mx:Button label="Load RSS" right="10" bottom="10" click="onLoadPress()"/>



import com.adobe.utils.XMLUtil;
import com.adobe.xml.syndication.rss.Item20;
import com.adobe.xml.syndication.rss.RSS20;

import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;

private var loader:URLLoader;

//url of rss 2.0 feed
private static const RSS_URL:String = "https://tournasdimitrios1.wordpress.com/feed/";

//called when user presses the button to load feed
private function onLoadPress():void
    loader = new URLLoader();

    //request pointing to feed
    var request:URLRequest = new URLRequest(RSS_URL);
    request.method = URLRequestMethod.GET;

    //listen for when the data loads
    loader.addEventListener(Event.COMPLETE, onDataLoad);

    //listen for error events
    loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);

    //load the feed data

//called once the data has loaded from the feed
private function onDataLoad(e:Event):void
    //get the raw string data from the feed
    var rawRSS:String = URLLoader(e.target).data;

    //parse it as RSS


//parses RSS 2.0 feed and prints out the feed titles into
//the text area
private function parseRSS(data:String):void

    //XMLSyndicationLibrary does not validate that the data contains valid
    //XML, so you need to validate that the data is valid XML.
    //We use the XMLUtil.isValidXML API from the corelib library.
        writeOutput("Feed does not contain valid XML.");

    //create RSS20 instance
    var rss:RSS20 = new RSS20();

        //parse the raw rss data

        //get all of the items within the feed
        var items:Array = rss.items;

        //loop through each item in the feed
        for each(var item:Item20 in items)
            //print out the title of each item

private function writeOutput(data:String):void
    outputField.text += data + "\n";

private function onIOError(e:IOErrorEvent):void
    writeOutput("IOError : " + e.text);

private function onSecurityError(e:SecurityErrorEvent):void
    writeOutput("SecurityError : " + e.text);

The code for parsing RSS 1.0 and ATOM feeds is pretty much the same as the example above, except instead of using the RSS20 class, you will use the RSS10 or Atom10 classes.

Note, that full API documents for the library are included in the library download.

What do you do if you don’t know the feed type before you parse it? Well, that is where the library really shines, as it provides a FeedFactory class which can automatically detect and parse any supported feed types. I will try and post an example of using the FeedFactory soon.

You can download the as3syndicationlib library from here.



1. Zelma - October 20, 2012

Very interesting details you have remarked, appreciate it for posting .

2. Stephan - October 20, 2012

I don’t normally comment but I gotta say appreciate it for the post on this perfect one : D.

3. hcg - October 20, 2012

Hello, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam feedback? If so how do you reduce it, any plugin or anything you can advise? I get so much lately it’s driving me mad so any assistance is very much appreciated.

tournasdimitrios1 - October 20, 2012

There are different ways to “fight” against spam . It all depends on what platform your website is build on .

4. Cletus - October 26, 2012

I like this site very much, Its a real nice situation to read and incur info .

5. whoop - October 26, 2012

I just added this webpage to my google reader, excellent stuff. Can’t get enough!

6. hcg - April 22, 2013

Excellent article. Keep writing such kind of information on your
site. Im really impressed by your site.
Hello there, You’ve done a great job. I will certainly digg it and personally recommend to my friends. I’m confident they will be benefited from this web

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s