How to Create a Flash Lite RSS Reader- Part 1

One of the easiest ways to push content to your mobile users is through an RSS feed. With an RSS reader, a mobile device can be set up to read feeds. Feeds themselves can be customized display differently on a mobile device. You can see this with the mobile version of this site, 2mlearn.mobi. There are several RSS readers available for mobile devices, the most popular is the one I use on my Blackberry, the Google Reader. For your users, however, a customized solution may be necessary. With Flash Lite, you can create a customized RSS reader that will work with many mobile devices.

Important Note: As you may know, Flash Lite does not parse XML directly. This may seem like a road block to creating an RSS reader, but it really is an easy obstacle to leap.


The first thing we�ll need to do is parse the XML feed and change it as to be loaded by Flash Lite. This is written in PHP, however, this could also be easily reproduced in Pearl, JSP, or with many other scripts.


First, define the link to the RSS feed:



$link_to_rss_feed ="http://mlearningworld.blogspot.com/feeds/posts/default";


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 a Flash Lite player&description1=New article on developing a Flash Lite player.



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.




Next week, we�ll explore building the player in Flash Lite for your mobile device. After that, we�ll discuss a strategy to choose what content to push out and when. Keep watching.



Share this

Related Posts

Previous
Next Post »