User Guide

332 Working with XML
The RSSViewer application files can be found in the folder Samples/RSSViewer. The
application consists of the following files:
Reading and parsing XML data
The RSSParser class includes an xmlLoaded() method that converts the input RSS data,
stored in the
rssXML variable, into an string containing HTML-formatted output,
rssOutput.
Near the beginning of the method, code sets the default XML namespace if the source RSS
data includes a default namespace:
if (rssXML.namespace("") != undefined)
{
default xml namespace = rssXML.namespace("");
}
The next lines then loop through the contents of the source XML data, examining each
descendant property named
item:
for each (var item:XML in rssXML..item)
{
var itemTitle:String = item.title.toString();
var itemDescription:String = item.description.toString();
var itemLink:String = item.link.toString();
outXML += buildItemHTML(itemTitle,
itemDescription,
itemLink);
}
The first three lines simply set string variables to represent the title, description and link
properties of the
item property of the XML data. The next line then calls the
buildItemHTML() method to get HTML data in the form of an XMLList object, using the
three new string variables as parameters.
File Description
RSSViewer.mxml The main application file in MXML for Flex.
com/example/programmingas3/rssViewer/
RSSParser.as
A class that contains methods that use E4X to
traverse RSS (XML) data and generate a
corresponding HTML representation.
RSSData/ak.rss A sample RSS file. The application is set up to
read RSS data from the web, at a Flex RSS
feed hosted by Adobe. However, you can easily
change the application to read RSS data from
this document, which uses a slightly different
schema than that of the Flex RSS feed.