XPath, Flash and RSS
Writing about web page http://www.xfactorstudio.com/ActionScript/AS2/XPath/
Grrr; want to try some experiments with Flash and a Warwick Blogs RSS feed, search Google for some pointers on parsing feeds using AS, can't find anything particularly useful so I attempt something anyway, after 2 hours this evening it's almost working but I'm stuck on something silly, try Google again, find a link to the Actionscript version of the XPathAPI, discover it's already built into Flash 7, and all I need is the classpath and to drag the Data Binding Classes into the Library to access a really easy way of navigating the feed. 10 mins later I have a lovely collection of arrays full of titles, items, authors etc. plugged into my display array function. I'm sure someone mentioned XPath to me before I started this. Next time I'll pay attention. For the record;
import mx.xpath.XPathAPI;
var rssfeed_xml = new XML();
rssfeed_xml.ignoreWhite = true;
rssfeed_xml.load("http://blogs.warwick.ac.uk/showall/newentries/?rss=rss_2_0");
rssfeed_xml.onLoad = function(success) {
if (success)
{ var titlePath:String = "/rss/channel/item/title";
title_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, titlePath);
for (var i = 0; i<title_array.length; i++)
{ trace(title_array[i].firstChild.nodeValue);}}}
etc..
No more of that nextSibling, firstChild multi-function rubbish for me. That turned 4 functions and about 100 lines of code into 20. Conscious incompetence, here I come…
Steven Carpenter


CpILL
I'm a bit stuck now? It seems you have to do all your work in the 'onload' method of the XML object you create, so what if you want to use it outside of this? I mean, how do you return anything from the 'onload', or do you have to write some kind of waiting loop?
13 Apr 2005, 14:33
Steven Carpenter
Hi CpILL – you are right that the heavy lifting is done within the onLoad; the onLoad statement basically says 'once you've successfully received this file, do this…' and the code above does that then store the values into an array title_array. Once that's done, you can pretty much throw that data around anywhere within your application by referencing title_array[n]. Does that answer your question?
13 Apr 2005, 14:45
Add a comment
You are not allowed to comment on this entry as it has restricted commenting permissions.