Monday, September 22, 2008

Working with XML Namespaces in Flash

Today I was having some issues with parsing RSS/ATOM feeds in Flash. I forgot to factor in the fact that both use namespaces in the XML. Here's a simple block of code I used to handle the namespaces and parse the XML into Value Objects:

public function xmlLoaded(event:Event):void


trace("done loading");

theXML = XML(;

var ns:Namespace = theXML.namespace();

for each (var property:XML in theXML..item)


var atom:Namespace = property.namespace("atom");

var fVO:FeatureVO = new FeatureVO();

fVO.pubDate = property.pubDate;

fVO.updated = property.atom::updated;

fVO.category = property.category;

fVO.title = property.title;

fVO.summary = property.atom::summary; =;

fVO.enclosure = property.enclosure.@url;

fVO.xmlData = property;


trace("creating featureVO "+fVO.enclosure);


This is what the sample xml looked like from Blogger's RSS/ATOM feed:

<rss xmlns:atom='' xmlns:openSearch='' version='2.0'>



<lastBuildDate>Wed, 10 Sep 2008 19:07:53 +0000</lastBuildDate>




<managingEditor> (Erik Loehfelm)</managingEditor>






<guid isPermaLink='false'>,1999:blog-</guid>

<pubDate>Wed, 10 Sep 2008 19:07:00 +0000</pubDate>


<category domain=''>feature</category>

<title>People Singing</title>

<atom:summary>This is going to be a feature for the portal.v/atom:summary>


<enclosure type='image/jpeg' url='' length='0'/>

<author> (Erik Loehfelm)</author>




You can see the syntax to be used on the 2 lines highlighted in bold above. The first defines the namespace (atom) and the second shows how you access elements in the xml that have the atom namespace applied to them.

No comments: