PDA

View Full Version : Question with RSS, Parsing as 1 XML Item


LoR*Evanescence
08-29-2008, 02:11 PM
I have a quick XML question for you all. I'm calling news in through a rss feed from a content management system now, instead of manually updating a xml file and reuploading it making it easier for others to update the news. However, now instead of each news item loading individual, they are loading as 1 news item smushed together. I have been playing with the code, but haven't gotten to the bottom of it yet so I was hoping some one here could give me a quick hand, thank you=)

here is the url to the RSS Feed: http://www.colettetrudeau.com/cutenews/rss.php?category=3

Here is the site in which it is loading so you can see what I mean by smushed: http://www.colettetrudeau.com

and here is my actionscript for loading the news

//news vars
var newsData:XML;//
var newsLoader:URLLoader = new URLLoader();
newsLoader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
newsLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
newsLoader.load(new URLRequest("http://www.colettetrudeau.com/cutenews/rss.php?category=3"));
var xmlNewsList:XMLList;
//End news

//start load news
function onComplete(evt:Event):void {
try {
newsData = new XML(newsLoader.data);
trace(newsData.channel.item.pubDate.text());
newsTextField.htmlText = newsData.channel.item.pubDate.text() + "\n" + newsData.channel.item.title.text() + "\n" + newsData.channel.item.description.text();
xmlNewsList = newsData.children();
trace("Number of News Items: " + newsData.length());
/*for (var n:int=0; n<xmlList.length(); n++) {
newsTextField.htmlText = xmlNewsList[n].item.title;
}*/
newsLoader.removeEventListener(Event.COMPLETE, onComplete);
newsLoader.removeEventListener(IOErrorEvent.IO_ERR OR, onIOError);
} catch (err:Error) {
trace("Could not parse loaded content as XML:\n" + err.message);
}
}
function onIOError(evt:IOErrorEvent):void {
trace("An error occurred when attempting to load the SML.\n" + evt.text);
}
//End news loader

Thanks for you help:cool:

Edit: odd, when I trace the pubDate I only get 1, but when I call it into my text box, I get them all
Edit: The number of news items traces 1 where it should be 2.

tank
08-29-2008, 02:48 PM
I think you were on the right track with your commented out section.

/*for (var n:int=0; n<xmlList.length(); n++) {
newsTextField.htmlText = xmlNewsList[n].item.title;
}*/

tank
08-29-2008, 02:50 PM
Sorry, I hit the submit button too soon. You should iterate through the items printing out each of the nodes and then move on to the next item.

LoR*Evanescence
08-29-2008, 02:56 PM
I think you were on the right track with your commented out section.

/*for (var n:int=0; n<xmlList.length(); n++) {
newsTextField.htmlText = xmlNewsList[n].item.title;
}*/


That is the direction I want to go, however, xmlList.length is reporting to be 1, instead of 2. So there is something else I need to fix before I can get the for loop working. This seems to be where i'm stuck:confused:

This is the output of my two traces:


Thu, 28 Aug 2008 17:06:18 -0400
Number of News Items: 1


Thanks for the reply

tank
08-29-2008, 03:00 PM
Ahh...if you are using that exact code above, you need to make a slight change. It should be xmlNewsList.item[n].title; not xmlNewsList[n].item.title; . Notice the placement of the [n].

LoR*Evanescence
08-29-2008, 03:35 PM
Well, I changed my code to this, and it only shows the latest news posting, but I can not get anything after to show, any idea's?

//start load news
function onComplete(evt:Event):void {
try {
newsData = new XML(newsLoader.data);
trace(newsData.channel.item.pubDate.text());
newsTextField.htmlText = newsData.channel.item[0].pubDate.text() + "\n" + newsData.channel.item[0].title.text() + "\n" + "\n" + newsData.channel.item[0].description.text();
xmlNewsList = newsData.children();
trace("Number of News Items: " + xmlNewsList.length());
for (var n:int=1; n<xmlNewsList.length(); n++) {
newsTextField.appendText ("\n\n" + xmlNewsList.channel.item[n].pubDate.text() + "\n" + xmlNewsList.channel.item[n].title.text() + "\n\n" + xmlNewsList.channel.item[n].description.text());
}
newsLoader.removeEventListener(Event.COMPLETE, onComplete);
newsLoader.removeEventListener(IOErrorEvent.IO_ERR OR, onIOError);
} catch (err:Error) {
trace("Could not parse loaded content as XML:\n" + err.message);
}
}
function onIOError(evt:IOErrorEvent):void {
trace("An error occurred when attempting to load the SML.\n" + evt.text);
}
//End news loader