rendered paste body// VARIABLES
_level0.error._visible = false; // Hide the error message
var feedArray = new Array();
var blogArray = new Array();
main(); // Call the main function to get this going
// function: main
// Description: Runs the program
// Output: void
function main()
{
getFeedArray(); // Get the feed array from the XML file
}
// function: getFeedArray
// Description: Fetches the feeds from an xml file
// Output: Array
function getFeedArray()
{
var feed_file = "feed_selector.xml"; // Select xml file
var feed_xml = new XML();
feed_xml.ignoreWhite = true;
feed_xml.onLoad = function(success) {
if (success) {
var array = processFeeds(feed_xml.childNodes,0);
_level0.feedArray = array;
}else{
//DISPLAY ERROR MESSAGE
_root.loading._visible = false;
_root.error._visible = true;
trace("can't fetch blog, try again");
}
};
feed_xml.load(feed_file); // Load xml
}
// function: processFeeds
// Description: Processes the XML file
// Input: Root XML Child
// Output: Array
function processFeeds(xmlitems, childnum)
{
var child = xmlitems[childnum];
switch(child.nodeName)
{
case "feed":
var str = child.firstChild.nodeValue; // Gets the feed string
//trace(str);
return "http://" + str.substring(7, str.length); // Replaces 'feed://' with 'http://'
break;
case "feeds":
feedArray = Array();
for(var d=0;d<child.childNodes.length;d++)
{
feedArray.push(processFeeds(child.childNodes,d));
}
return feedArray;
break;
default:
trace("Malformed XML file.");
return null;
break;
}
}
// function: getBlogArray
// Description: Takes the feeds and gets the blog information
// Input: Array populated addresses to feeds
// Output: Array
function getBlogArray(feedArray)
{
var blogArray = Array();
for(var i=0;i<feedArray.length;i++)
{
blogArray.push(fetchBlog(feedArray[i]));
}
for(var i in blogArray){
for(var j in blogArray[i]){
trace(i+"-"+j+": "+blogArray[i][j]);
}
}
return blogArray;
}
// function: fetchBlog
// Description: Takes the feeds and gets the blog information
// Output: Array
function fetchBlog(feed)
{
var blog_xml = new XML();
blog_xml.ignoreWhite = true;
blog_xml.onLoad = function(success) {
if (success) {
var dataArray = processBlog(blog_xml.childNodes,0,false);
return dataArray;
}else{
//DISPLAY ERROR MESSAGE
_root.loading._visible = false;
_root.error._visible = true;
trace("can't fetch blog, try again");
}
};
blog_xml.load(feed); // Load xml
}
function processBlog(xmlitems, childnum, isItem)
{
var child = xmlitems[childnum];
dataArray = new Array();
switch(child.nodeName)
{
case "rss":break;
case "title":
if(isItem)
{
dataArray = {item_title: child.firstChild.nodeValue};
}else{
dataArray = {blog_title: child.firstChild.nodeValue};
}
break;
case "link":
if(isItem)
{
dataArray = {item_link: child.firstChild.nodeValue};
}else{
dataArray = {blog_link: child.firstChild.nodeValue};
}
break;
case "description":
if(isItem)
{
dataArray = {item_description: child.firstChild.nodeValue};
}else{
dataArray = {blog_description: child.firstChild.nodeValue};
}
break;
case "language":
dataArray = {blog_language: child.firstChild.nodeValue};
break;
case "item":
for(var d=0;d<child.childNodes.length;d++)
{
dataArray.push(processBlog(child.childNodes,d,true));
}
var tmp = dataArray;
for(var i in tmp){
for(var j in tmp[i]){
dataArray[j] = tmp[i][j];
}
}
break;
case "comments":
dataArray = {item_comments: child.firstChild.nodeValue};
break;
case "category":
dataArray = {item_category: child.firstChild.nodeValue};
break;
case "pubDate":
dataArray = {item_pubdate: child.firstChild.nodeValue};
break;
case "dc:creator":
dataArray = {item_creator: child.firstChild.nodeValue};
break;
case "guid":
dataArray = {item_guid: child.firstChild.nodeValue};
break;
case "channel":
for(var d=0;d<child.childNodes.length;d++)
{
dataArray.push(processBlog(child.childNodes,d,false));
}
var tmp = dataArray;
for(var i in tmp){
for(var j in tmp[i]){
dataArray[j] = tmp[i][j];
}
}
break;
default:
trace("Malformed XML file.");
return null;
break;
}
return dataArray;
}