RSS 2 file reader
CODE
onload() { // cybernetix 13dots.com
// news source file
sourcefile = "rss2_news.xml";
// this one will search all nodes, if parameter direction is true
// it will step forward, otherwise it wil step back 1 node
//
/* it is fast as a devil by himself, maybe even faster;) */
XMLNode.prototype.goNextNode=function(direction) {
if (direction) { // if true step forward 1 node
// bingo, first one has content, thats what we are looking for
if (this.firstChild!=null) return this.firstChild;
var nodVal=this;
// search next
while (nodVal.nextSibling==null) {
// no further nodes, brake and return null
if (!nodVal.parentNode) return null;
nodVal=nodVal.parentNode; // found something
}
// return this one, it has something in it
return nodVal.nextSibling;
}
else { // if false step back 1 node
// in this example we don't need this one, but you can use it
// for all xmls reading
// no previous, return this one again
if (!this.previousSibling) return this.parentNode;
var nodVal=this.previousSibling;
// search previous node
while (nodVal.lastChild) {
nodVal=nodVal.lastChild;
}
// return this one
return nodVal;
}
};
// create xml object
xmlNews=new XML();
// load file
xmlNews.load(sourcefile);
xmlNews.ignoreWhite=true; // must be true
xmlNews.onload=function(success) { // load
if (success) { // file is there, ok
// make copy of original, this is not neccessary, but it is handy, you can
// later just change name of object xmlNews
var xNode=xmlNews;
// this is dynamic text filed which will receive text
// NOTE: must be with HTML rendering option!
_root._rssText.text="";
// initiate vars
var lastNodeName="", lastPermaLink=false, channelString="";
// ok, lets go
while (xNode.goNextNode(true)) {
xNode=xNode.goNextNode(true);
if (xNode.nodeName=="rss") {
// channel mode
channelString+="<b>"+xNode.nodeName+": "+xNode.attributes.version+"</b><br>";
} else if (xNode.nodeName=="channel") {
// just channel
channelString+="<u><b>"+xNode.nodeName+"</b></u><br><br>";
} else if (xNode.nodeName=="item") {
// we are in news section, define newsString, couse until it is not defined
// we are reading channel info
if (newsString==undefined) var newsString="";
newsString+="\n";
} else if (xNode.nodeName!=null) {
// node names
if (newsString==undefined) { // if we are still on channel info, read node into channel string
channelString+="<b>"+xNode.nodeName.toUpperCase()+": "+"</b>";
} else { // we are in news section, read node into news string
newsString+="<b>"+xNode.nodeName.toUpperCase()+": "+"</b>";
}
lastNodeName=xNode.nodeName; // remember this one for later use
if (lastNodeName=="guid") { // if it is guid for permanent link
// there are a few options, lets see all of them
if (xNode.attributes.isPermaLink!=undefined) {
// isPermaLink is defined, just write it down
lastPermaLink=xNode.attributes.isPermaLink;
} else {
// isPermaLink not defined, means it is true
lastPermaLink="true";
}
} else {
// we are not on guid node, so we don't need this one
lastPermaLink="false";
}
} else if (xNode.nodeValue!=null) {
// node values
if (newsString==undefined) { // if we are still on channel info, read node into channel string
if (lastNodeName=="link") {
channelString+="<u><a href='"+xNode.nodeValue+"' target='_blank'>"+"Transfer to page"+"</a></u><br>"+"\n";
} else {
channelString+=xNode.nodeValue+"\n";
}
} else { // we are in news section, read node into news string
if (lastNodeName=="link") { // it it is link write it down with html render
newsString+="<u><a href='"+xNode.nodeValue+"' target='_blank'>"+"Transfer to page"+"</a></u><br>"+"\n";
} else if (lastNodeName=="guid") { // we are on guid
if (lastPermaLink=="true") { // we have a permanent link, write it down with html render
newsString+="<u><a href='"+xNode.nodeValue+"' target='_blank'>"+"Permanent link"+"</a></u><br>"+"\n";
} else { // there is no permanent link
newsString+=xNode.nodeValue+"\n";
}
} else { // write down other nodes
newsString+=xNode.nodeValue+"\n";
}
}
}
}
// finished, lets see what the news are
_root._rssText.text=channelString+"\n\n"+"<u><b>news section</b></u><br><br>"+newsString;
} else {
// news source file not found
javascript("alert('file not found: "+sourcefile+"')");
}
};
}
you can test it hereyou can find source swi and xml files in download section
herebeta version of RSS2 reader/feeder can be reviewed :: HERE ::