Accessibility

Table of Contents

Creating a Flash Lite 1.1 RSS Reader

Creating the RSS parser

The following online content can be fed to the Flash Lite 1.1 RSS reader using the same RSS parser:

  • blogs
  • news
  • forums
  • podcasts
  • videocasts

All these web content types are currently available as XML feeds using RSS 1.0, RSS 2.0, RDF, or Atom specifications.

For this example I will develop the RSS parser on the server using PHP 5 programming language. You can use your favorite programming language such as ColdFusion, JSP, ASP, or Perl to achieve the same results. The server script is the base framework from which you can start building a more sophisticated RSS parser. For this example you will parse the RSS 2.0 feed from the following web address: http://www.flashmobilegroup.org/?feed=rss2

Here is how an RSS 2.0 XML feed section looks like:

<rss version="2.0">
−<channel>
    <title>Flashmobilegroup.org</title>
    <link>http://www.flashmobilegroup.org</link>
    <description/>
    <pubDate>Tue, 06 Jun 2006 12:51:45 +0000</pubDate>
    <generator>http://wordpress.org/?v=1.5.2</generator>
    <language>en</language>
    <item>
        <title>Tips for Developing Flash Games for the iRiver U10</title>
        <description>New article on DevNet at Adobe: Tips for Developing Flash Games for the iRiver U10. It includes two samples available for download.
        The article is written by Sung-Hee Park of MiniGate. Alessandro
        </description>
    </item>
    ............
    ............
    ............
<channel>

You will parse this RSS 2.0 feed to extract the <title> and <description> tags contents for each <item> block, and then customize the content to be able to load it into the Flash Lite 1.1 RSS reader on the mobile phone.

I chose PHP 5 as the server-side scripting language because it has a very simple XML parsing API. Here is the script:

//Link to RSS 2.0 feed
$link_to_rss_feed ="http://www.flashmobilegroup.org/?feed=rss2";

//Counter to append to &variables to return to the client
$i=1;

// This PHP 5 function loads the entire XML feed
$xml = simplexml_load_file($link_to_rss_feed);

// Parse each item in the RSS feed
foreach    ($xml->channel[0]->item as $item)
{
    if($item) {
        // Need to strip html tags since Flash Lite does not support 
        // html in dynamic text fields
        $title = strip_tags($item->title);
        $description = strip_tags($item->description);
        
// Replace special symbols &
        $title = str_replace("&", "", $title);
        $description = str_replace("&", "", $description);
        
// Return the content with the appropriate index
        echo "&title$i=".$title;
        echo "&description$i=".$description;
        //echo $i;
        $i++;
    } else {
        // Send and Error message if content is not found
        echo "&msg=Content not found";
        echo "&flag=error";
        echo "&end=end";
        exit;
    }
}
$i=$i-1;
echo "&flag=ok";
echo "&totalitems=".$i;
echo "&end=end";

Analyzing the code

Define the link to the RSS 2.0 feed:

$link_to_rss_feed ="http://www.flashmobilegroup.org/?feed=rss2";

The link above will be the input of the simplexml_load_file PHP 5 function call as described below:

$xml = simplexml_load_file($link_to_rss_feed);

The $xml variable will now contain the entire XML feed from the above link. Notice that the above function can access XML content directly from the Internet, but it is subject to security restriction of your PHP server engine (visit www.php.net for more details).

At this point you are interested in parsing each <item> node and selecting the content of <title> and <description> to be returned to the Flash Lite 1.1 application. For this reason you use the foreach function to loop each node and extract the content.

First you need to strip out HTML tags from the text contained in the <title> and <description> tags. Do this by using the strip_tags function. Flash Lite 1.1 dynamic text does not support HTML tags.

Also—and this is very important—you must strip out any & symbol contained in the text enclosed in the <title> and <description> tags. You do this using the str_replace function. Flash Lite 1.1 recognizes variable data loaded by having a & symbol as the prefix, so any & contained in the text will break this data structure.

The following two lines will create the & name/value pair data structure for the title and description, which will be the variables used in the Flash Lite 1.1 RSS reader:

echo "&title$i=".$title;
echo "&description$i=".$description;

The above echo will return the following output for the first <item> block:

&title1=Tips for Developing Flash Games for the iRiver U10&description1=New article on DevNet at Adobe: Tips for Developing Flash Games for the iRiver U10. It includes two samples available for download. The article is written by Sung-Hee Park of MiniGate. Alessandro

Because an RSS feed contains more item nodes, you will end up having several &title and &description data, such as &item1, &description1, &item2, &description2, and so on. Append the loop index $i to each item and description variable to create a different set of each node.

The &totalitems is the total number of items parsed and the &end variable is the flag that we will use to indicate to Flash Lite 1.1 that the data is over.

Flash Lite 1.1 does not have the capability to check for the end of data. So the solution to this problem is to return a flag at the end of the data.

Note: You can use other methods to achieve the same results. Also keep in mind that you will probably need more error checking.

At this point, you have built the main structure of the server RSS parser. Place the file on your server that is accessible from the Internet. To test the parser, just enter the link to the script into a browser.