RSS parser package in Flash ActionScript
Download
Usage
Preparation
Unzip downloaded file and copy the package (whole "com" folder) to predefined path. You can set the package into...
1. The document-level classpath where same path as your ".fla" document files exists.
...or
2. The global classpath listed below where that's shared by all of your Flash documents.
Simple sample
This simple sample loads RSS feeds and shows its Object tree in trace window of flash IDE.
Import sentence is required for use of this package as line 2 in this sample code.
// import package
import com.cybozuLab.rssParser.*;
// create FetchingRss class instance
// set the target RSS URL
var rssObj:Object = new FetchingRss( "http://www.example.com/index.xml" ); // change exist URL
// pointer to this MovieClip
var thisObj = this;
// define the function when loading is completed
rssObj.onLoad = function( successFL, errMsg )
{
if( successFL )
{
// trace the object, result of parsing
Utils.traceObj( this.getRssObject() );
}
else
{
trace( errMsg );
}
}
// start loading
rssObj.load();
Simple sample 2
This simple sample loads RSS feeds and shows its posts summary in trace window of flash IDE.
// import package
import com.cybozuLab.rssParser.*;
// create FetchingRss class instance
// set the target RSS URL
var rssObj = new FetchingRss( "http://www.example.com/index.xml" ); // change exist URL
// pointer to this MovieClip
var thisObj = this;
// define the function when loading is completed
rssObj.onLoad = function( successFL, errMsg )
{
if( successFL )
{
// call function for listing summary
thisObj.listSummary();
}
else
{
trace( errMsg );
}
}
// start loading
rssObj.load();
function listSummary()
{
var rssData:Object = rssObj.getRssObject();
for( var i=0; i<rssData.channel.item.length; i++ )
{
var post:Object = rssData.channel.item[i];
trace( "---------------------------------" );
trace( post.pubdate.value );
trace( post.title.value );
trace( post.description.value.substr( 0, 60 ) + "\n" );
}
}
Other samples
Reference
- url:String --- A string that represents the URL where the RSS feed to be loaded. If you let the SWF running in a web browser issue this call, the url must be in the same domain as the SWF file. (You can get feeds in other domains via web proxy in your domain.)
var myRss:FetchingRss = new FetchingRss( "http://www.simple-example.com/somebody/index.xml" );
- success:Boolean --- A Boolean value that evaluates to true if the RSS data is loaded and parsed successfully. Otherwise, false.
- errorMessage:String --- A String that represents the detail of error status.
import com.cybozuLab.rssParser.*;
rssObj = new FetchingRss( "http://www.example.com/index.xml" );
thisObj = this;
rssObj.onLoad = function( successFL ){
if( successFL ){
trace( Utils.objToString( thisObj.rssObj.getRssObject() ) );
}else{
trace( thisObj.rssObj.getErrorMessage() );
}
}
rssObj.load();
Loads an RSS document from the specified URL, and parses downloaded XML object for storing the data in Object instance. The URL is relative and is called using HTTP. The loading process is asynchronous, therefor it does not finish immediately after the load() method is called.
When the XML data finishes downloading and parsing, the onLoad event handler is invoked.
- url:String --- A string that represents the URL where the RSS feed to be loaded. If you set this parameter, load method overwrites the url parameter you passed at creating instance. If you let the SWF running in a web browser issue this call, the url must be in the same domain as the SWF file. (You can get feeds in other domains via web proxy in your domain.)
- sourceData:XMLNode --- A XMLNode object that contains the RSS feed to be parsed.
var myRss:ParsingRss = new ParsingRss( rssNode );
- targetObj:Object --- An Object for counting its elements.
- targetObj:Object --- An Object for converting to a String.
- targetObj:Object --- An Object for tracing.
Todo
- Handling multi enclosure tags in each item tag.
- Let be compatible with RSS 0.9, 1.0 and Atom feed.
Version History
0.22: [24/May/2006]
- Utils.traceObj handles both of Array and Object
0.21: [18/May/2006]
- Enebled to access the result with lower-case object key as well as mixed-case.
- Change the type of return value which contains each item. ( object -> array )
0.2: [14/Feb/2006]
- Changed the timing of parsing loaded RSS
Links
- My office, Cybozu Labs, Inc.
- My blog, shortnote