Parsing RSS 2.0 Feeds in ActionScript 3
One of the ActionScript libraries that I use most 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, although I have separated the code to make it easy to also use it within Flash CS3.
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).
RSSExample.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script source="RSSExampleClass.as" />
<mx:TextArea left="20" top="10" bottom="40" right="10" id="outputField"/>
<mx:Button label="Load RSS" right="10" bottom="10" click="onLoadPress()"/>
</mx:Application>
RSSExampleClass.as
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 = "http://feeds.feedburner.com/MikeChambers/";
//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
loader.load(request);
}
//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
parseRSS(rawRSS);
}
//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.
if(!XMLUtil.isValidXML(data))
{
writeOutput("Feed does not contain valid XML.");
return;
}
//create RSS20 instance
var rss:RSS20 = new RSS20();
//parse the raw rss data
rss.parse(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
writeOutput(item.title);
}
}
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.






How does this work with the security sandboxing? I presume FeedBurner allows anyone to download their feeds?
Mark Ingram
22 Jan 08 at 1:48 pm
Works the same as loading any other remote data. All crossdomain and security restrictions apply.
mike chambers
mesh@adobe.com
mikechambers
22 Jan 08 at 1:54 pm
You may like the AMFPHP + MagpieRSS way I use to parses out RSS.
There are a few key reasons why I like to use a remote method for getting something as simple as an RSS feed.
1): No restrictions. No need to worry about crossdomain.xml. That has to be the one thing the stops people from using RSS in flash. There is A lot of RSS feeds out there “Like Netflix” that don’t provide a crossdomain.xml file requiring you to use some form of proxie to get around it. This can also be worked around by using Yahoo’s pipes as a kinda proxie for getting around crossdomain problems
2): Scalability. If you know much about php for this example you could use Magpie’s Integrated Object Caching or leverage the power of php to make use of something more then just a RSS feed only.
3): Usability. This is very simple to impalement, though you may need some prior knowledge of php and flash remoting. Once installed you can make a remote call from flash and pass it the url and get an array back ready to use any way you want.
I made a mini tutorial at http://gfxcomplex.com/blog/amfphp/overcome-flash-and-rss-crossdomain-problems-with-amfphp-and-magpie/
Josh Chernoff
22 Jan 08 at 4:37 pm
Very usefull example thanks for posting, nice and short
julien
24 Jan 08 at 3:55 am
[...] Chambers shows how to use the as3syndicationlib actionscript library to parse RSS 2.0 Feeds in ActionScript 3. Tags: Actionscript, Atom, Mike Chambers, [...]
Parsing RSS/ATOM in ActionScript 3 | David Bisset: Web Designer, Coder, Wordpress Guru
24 Jan 08 at 8:03 am
Great library. A couple things to note:
Despite it being called as3syndicationlib and not mentioning flex, it actually has references to a few flex classes and won’t work in an actionscript only project unless you modify the classes and replace these references.
Its missing a few popular modules namely the Yahoo Media module that most media syndication feeds use.
I wish the framework was a bit simpler or dynamic in incorporating additional modules as right now its a fairly intricate process.
Adobe has released a sample Flex 3 app called Media Widget and the company that developed it, Teknision, used this library for its feed parsing. They’ve modified it adding the Yahoo Media module among other improvements and this updated source is available in Media Wiget source code. The “official” project code hasn’t been updated in over a year and doesn’t reflect these changes.
Overall a class not to live without for any syndication parsing project :)
Mark
24 Jan 08 at 8:57 am
>Great library. A couple things to note:
Well, it is an open source community project, so if anyone would like to add that, or other functionality, just let me know.
mike chambers
mesh@adobe.com
mikechambers
24 Jan 08 at 9:57 am
I wouldn’t mind adding some of the things I noted when I find the time but the main thing I wanted to mention in that blob of text is that an updated version of the library is accessible in the Media Widget sample code with flex 3 that has more media feed parsing functionality and namespaces built in, until the library itself is updated–might save someone some time.
Mark
24 Jan 08 at 12:22 pm
More on Parsing Feeds with Flex/AS3
Several days ago I posted a couple lines of code that came in quite handy while parsing an Atom feed. Mike Chambers has put together a more in depth post on parsing Atom/RSS feeds using the as3syndica…
T3B
26 Jan 08 at 5:42 pm
Cant the data be requested using JS nad passed on to the swf for parsing to overcome the crossdomain.xml restrictions?
PL/SQL
26 Jan 08 at 7:23 pm
Nice example. How do you take care of media-rss etc? I have to hack as3syndicationlib and add those media-rss capabilities.
It would be great to see an example that shows extending as3syndicationlib for various extentions (creativeCommons, a9, media-rss etc).
Thanks
-abdul
Abdul Qabiz
27 Jan 08 at 8:52 am
[...] Parsing RSS Feed January 27, 2008 — drawk Mike Chambers has a great post on parsing RSS in AS3 with as3syndicationlib. I had some info on this but this feed is very simple and just posting the [...]
AS3 Parsing RSS Feed « [ draw.logic ]
27 Jan 08 at 7:41 pm
>Cant the data be requested using JS nad passed on to the swf for parsing to overcome the crossdomain.xml restrictions?
Yes, although JS crossdomain restrictions are much stricter than Flash’s (Flash has a permission based way around them via crossdomain.xml).
mike chambers
mesh@adobe.com
mikechambers
28 Jan 08 at 10:07 am
>How do you take care of media-rss etc? I have to hack as3syndicationlib and add those media-rss capabilities.
Ill try and see if I can get Christian to respond, but you can grab individual raw items from the feed in order to extend the parser.
mike chambers
mesh@adobe.com
mikechambers
28 Jan 08 at 10:09 am
Hello,
I’m trying to get your example to work with Flash CS3 but I ran into a problem.
ReferenceError: Error #1065: Variable mx.utils::StringUtil is not defined.
at com.adobe.xml.syndication::ParsingTools$/nullCheck()
at com.adobe.xml.syndication.rss::RSS20/get items()
at main/parseRSS()
at main/onDataLoad()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
In ParsingTools.as I found:
import mx.utils.StringUtil;
This class [mx.utils.StringUtil] seems to be part of the Flex library and not in Flash CS3, any suggestions on how I can get this to work?
Dave
30 Jan 08 at 6:42 am
Make sure to link in the corelib library:
http://code.google.com/p/as3corelib/
mike chambers
mesh@adobe.com
mikechambers
30 Jan 08 at 9:00 am
I am importing the as3corelib package and can reference them. From what I can tell all the packages in as3corelib are packaged as com.adobe.[name].[name] But in ParsingTools.as it imports mx.utils.StringUtil - different package name. To test I wasn’t doing anything too crazy I created a new flash file and tried this.
———————
import mx.utils.StringUtil;
var s:String =”adfadfaf”;
trace(StringUtil.trim(s).length == 0)
———————
the result was this:::
ReferenceError: Error #1065: Variable mx.utils::StringUtil is not defined.
at testUtil_fla::MainTimeline/frame1()
———————
Are you able to get it to work using Flash CS3?
Dave
30 Jan 08 at 12:17 pm
>mx.utils.StringUtil
Ahh, actually, that is the Flex String utils. I just checked the code, and if you change the import from:
mx.utils.StringUtil
to
com.adobe.utils.StringUtil
It should work (the second is the StringUtil in corelib).
I try and update the library with this fix soon.
mike chambers
mesh@adobe.com
mikechambers
30 Jan 08 at 12:32 pm
That did the trick.
Thanks!
Dave
30 Jan 08 at 12:38 pm
Hello,
Could you provide a sample of how to retrieve “media” from an RSS20Item. I’ve been trying but the media property always returns null. Other properties such as link or id do return values.
Thanks
Dave
31 Jan 08 at 3:40 pm
Hello, i ran into an issue with the DateBase class and Flash CS3. I think it’s the mx.formatters.DateBase classe from Flex i think.
It’s not available in the as3corelib but it is accessed threw syndication lib. Is there a workaround similar to the StringUtil class?
DateBase class is used by the DateUtil class from the as3corelib (com.adobe.util - package).
thanks, hannes
Hannes Moser
5 Feb 08 at 4:14 pm
Same issue as Hannes.
DateUtil.as imports mx.formatters.DateBase which doesn’t appear to be a class of either the syndication or corelib packages.
Steve Nelson
6 Feb 08 at 2:35 pm
Steve
I made this little class that I put in ‘com.adobe.utils’, which contains JUST ENOUGH to get the syndication API going. You can get the source here:
http://www.newcommerce.ca/as3/DateBase.as
Simply change the instances of:
import mx.utils.DateBase;
by:
import com.adobe.utils.DateBase;
BTW: Somebody might want to doublecheck this, as I’m not 100% sure it’s correct.
:)
Martin Legris
8 Feb 08 at 11:59 am
Thank you Martin!
Mike: Once I made that substitution and tried again to compile, the mx.utils.StringUtil class was requested, but when I changed that to com.adobe.utils.StringUtil it finally compiled and worked. I really appreciate your help Martin, and Mike I really appreciate this information.
Steve
Steve Nelson
9 Feb 08 at 2:19 pm
Mike,
Thanks for the great tutorial. Your code made it easy to get a jump start on working with the library. This post inspired me to build a simple app that uses a Yahoo Pipes RSS feed (combining snap previews with digg stories). I ended up using a php caching script to get around crossdomain issues.
Here is the demo w/source:
http://infinitearray.com/blog/2008/02/yahoo-pipes-flex.html
Ryan Robinson
10 Feb 08 at 6:00 pm
I’ve extended the as3syndicationlib so that you can use it with Media RSS. There are about ten new classes that represent all the media rss elements. All Media RSS tags must be within the “media:content” tag, groups and more than one element of the same tag are not supported at the moment.
You can download the very first version in the comments of this post:
http://www.video-flash.de/index.php/as3syndicationlib-rss-und-atom-feeds-mit-actionscript-3-parsen/#comments
Flo
20 Feb 08 at 2:46 pm
I’m getting errors when importing the SWC (I have Corelib SWC imported already). I narrowed down the bug to be in the RSS20.
If I just create a RSS20 object I get two errors:
Unable to resolve resource bundle “formatters” for locale “en_US”.
Unable to resolve resource bundle “SharedResources” for locale “en_US”.
Danny
22 Feb 08 at 7:27 am
sorry, i can’t find your email, so i’m posting it here.
i think you’ve been plagiarized…
http://www.elokcomputer.web.id/2008/02/09/parsing-rss-20-feeds-in-actionscript-3/
Ted
9 Mar 08 at 6:52 pm
Hi,
Just wanted to remind you about this:
http://www.mikechambers.com/blog/2008/01/22/parsing-rss-20-feeds-in-actionscript-3/#comment-10994
I had the same issue.
Thanks
Adam Bowman
16 Mar 08 at 8:06 am
Awesome! I’m using this with Yahoo Pipes (to combat cross-domain issues) to build a feed reader. It works a darn treat! Cheers Mike!
Ed
18 Mar 08 at 10:42 am
@Ed - I’m trying to use Pipes in the very same way but still receiving crossdomain security errors (SecurityError: #2048).
Would you mind explaining how you are able to use Pipes to bypass Flash’s built-in crossdomain enforcement?
Thanks.
- Chris
Chris
25 Mar 08 at 12:30 pm
Chris, the way I did it was to set up a simple pipe to parse a feed of the user’s choosing, using the Pipes url input and fetch modules. I then set up Flash to parse the resulting Pipes feed address (using the as3syndicationlib) along with the request url of the feed address. Oh, and you have to use the yahooapis.com domain for your request URL as that’s where the vital crossdomain.xml policy file lives on Yahoo’s servers. So your request URL should look something like this (replace the capital letters and hyphens accordingly):
http://pipes.yahooapis.com/pipes/pipe.run?_id=PIPE-ID&_render=rss&NAME-OF-URL-INPUT-MODULE=http://URL-OF-FEED
Hope that helps!
Ed.
Ed
26 Mar 08 at 11:16 am
Ed,
Great - thanks! That is a vital piece of information that I didn’t find on Yahoo! Pipes. I need to look better next time.
I need to look at the API and see if it’s possible to add feeds to a pipe progmatticaly as that would be sweet.
Thanks.
Chris
31 Mar 08 at 12:29 pm
Ed,
Pardon me but do you know if it possible to bypass the need for a pipe - or - to simply isolate a single RSS feed URL and access it directly through yahooapis.com/pipes?
I see what might be a snippet of that in your “&NAME-OF-URL-INPUT-MODULE”.
Basically, I have a list of feeds stored in our Oracle database that the user is able to customize. When selecting one of those feeds, I’m currently use DBMS_XMLQuery to extract the values using HTTPURITYPE.getXML(). The problem with this approach is that my XML output doesn’t come back with an header, therefore Adobe Flex is kinda like “Huh?” when it sees the output.
Since I can’t find an approach to inserting an feed directly into a Pipe (thinking about it, that would be pretty hard to do since the user has to connect feeds to outputs, etc.); I was thinking that might be able to access an RSS url through Yahoo Pipes without the need for having that feed inside of an already created pipe.
Does that make sense? Look forward to seeing your response.
Thanks.
Chris
31 Mar 08 at 1:03 pm
Hello everyone.
Trying to parse the following feeds, I get an “Unable to determine feed type”!
http://www.heise.de/security/news/news.rdf
http://www.heise.de/newsticker/heise.rdf
Why? I think this is normal rss 1.0…
Thanks for any suggestions!
Greetings,
Tim.
Tim
21 Apr 08 at 2:02 am
How can this library be compiled/ build???
Is there a way doing it using Flex 2.0 on WinXP?
Greetings and thanks,
Tim.
Tim
21 Apr 08 at 7:04 am
I would want to use this in Flash CS3 (no Flex). Any chance someone could give me (and others) some points as to how to do that? I’ve tried and not getting anywhere…
Magnus
7 May 08 at 9:16 am
[...] suposed to be informative and quick. In regards to use the FlashDevelop IDE and it is based off of Mike Chambers [...]
i-create | therefore-i am » Blog Archive » FlashDevelop Quick Start
18 May 08 at 10:27 am
This solution pared with Yahoo! Pipes worked like a charm. Good stuff, good stuff.
John
27 May 08 at 2:42 pm
Hi, I used the library in my application to read RSS feeds but for some reason it only works in IE and not Firefox??? When the Firefox browser begins to load the RSS, it will display “Transferring data from …” or “Reading RSS …” but it just stays like that forever. Nothing actually happens. Please help if you can. Thanks in advance.
Sam
28 May 08 at 10:01 am
*** For those wanting to use this stuff in Flash CS3… ***
I too came up against the problem of certain classes failing to import in Flash (the mx ones)… but with some good old fashioned digging, I found that the old “mx.formatters.DateBase” class was really close to a class included by Adobe in their “Programming Actionscript 3″ examples… I added a couple of static arrays for month and day names and it started to work. In addition, there were just some problems with things like “StringUtils” being moved into different packages with the porting to AS3, so I updated the “import” directives to take care of that.
The bottom line is “IT ALL WORKS” - based on Mike’s code above, I have uploaded a ZIP of the above work, (including the corelib classes) at http://www.g-raff.com/downloads/syndicationExample.zip - maybe someone can assist me in letting me know the correct protocol for adding this new ported “DateBase” class to the corelib?
Anyway - this example is specifically for users of Flash - a syndication example that just does exactly what Mike is doing above, but including the FLA and a little SyndicationExample.as file that I just wrote - its basically a template method so you can take it from there. In addition, my file takes the URL of the feed as a single argument, so you are not restricted to one feed… you’ll see when you open the files.
Thanks for the starting point, Mike.
Steve jones
Steve Jones
31 May 08 at 1:26 am
Hi Mike!
Thanks for the examples and classes. I just submitted a patch to the library for GeoRSS support. It’d be great to see it integrated, as I’m going to be recommending people use this framework in the Flasj Maps API for parsing GeoRSS feeds.
- pamela
Pamela Fox
4 Jun 08 at 1:53 pm
In this tutorial by Lee Brimelow, he showcases how to parse XML with the kuler namespace. http://www.gotoandlearn.com/player.php?id=65
I am just wondering if it POSSIBLE to parse mediaRSS without the use of all these libraries, just using the techniques shown by Lee Brimelow?
Marcus
23 Jun 08 at 12:46 am
[...] Parsing RSS 2.0 Feeds in ActionScript 3 [...]
Tutorials | Creating RSS readers with Flash and Flex « Flash Enabled Blog
10 Jul 08 at 2:59 pm
[...] Parsing RSS 2.0 Feeds in ActionScript 3 ???????http://blog.minidx.com/2008/07/21/1112.html [...]
ActionScript 3???as3syndicationlib?corelib?????RSS 2.0??? - ??Flex??
20 Jul 08 at 9:34 pm
To Martin Legris and all those using his DateBase.as.
Thought might be good to let everybody know its missing August in both months array.
Thanks for all the good works
jp
jpye
18 Aug 08 at 2:52 am
[...] Steve Jones ran across the same errors earlier, fixed them, and shared his solution on Mike’s [...]
Google Groups to Google App Engine: you seem a little shifty to me! at Aral Balkan
20 Aug 08 at 8:31 am
Hi Mike,
Thanks a lot for this sample :)
It’s just working so nicely! I think I’ll add rss everywhere in my projects now :p
SeeYa!
Jean-Christophe TURIN
27 Aug 08 at 2:47 am
Ed or who may be able to help,
Where and how do you place the policy XML file required by flash in yahoo pipes?
I need thie to point at my domain (of course).
Many thanks in advance!
Elliot
Elliot R
1 Sep 08 at 2:44 am
Ok I found all the obvious information to answer my “late night” question above.
I am still having issues with the correct URL on pipes to load my RSS feed from as3.
@Ed,
Is it possible for you to provide examples of your pipes setup and how you implemented it in as3, please.
Cheers
Elliot
Elliot R
1 Sep 08 at 5:36 pm