旅途笔记

岂有豪情似旧时,花开花落两由之
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

actionscript读取RSS代码分析

Posted on 2007-04-10 19:29  allonkwok  阅读(284)  评论(0编辑  收藏  举报

stop();
//----运行----
//加载XML
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load(targetXML);
onEnterFrame = function () {
 loadingXML();
};
//----变量声明----
var ChannelArr = new Array();
itemNum = 0;
itemTitle = new Array();
itemCategory = new Array();
itemLink = new Array();
itemDescription = new Array();
//----函数声明----
//分析XML
function perseXML() {
 //将数据读入数组ChannelArr
 channelFolder = myXML.firstChild.childNodes[0].childNodes;
 //定位到<channel>的子节点
 channelNodesFolder = channelFolder.length;
 for (i=0; i<channelNodesFolder; i++) {
  switch (channelFolder[i].nodeName) {
  case "title" :
   channelTitle = channelFolder[i].childNodes[0].nodeValue;
   break;
  case "link" :
   channelLink = channelFolder[i].childNodes[0].nodeValue;
   break;
  case "description" :
   channelDescription = channelFolder[i].childNodes[0].nodeValue;
   break;
  case "pubDate" :
   channelPubDate = channelFolder[i].childNodes[0].nodeValue;
   break;
  case "item" :
   perseItem();
   break;
  }
 }
}
function perseItem() {
 itemNodesFolder = channelFolder[i].childNodes;
 //定位到Item的子节点
 itemNodesCount = itemNodesFolder.length;
 for (j=0; j<itemNodesCount; j++) {
  switch (itemNodesFolder[j].nodeName) {
  case "title" :
   itemTitle[itemNum] = itemNodesFolder[j].childNodes[0].nodeValue;
   break;
  case "category" :
   itemCategory[itemNum] = itemNodesFolder[j].childNodes[0].nodeValue;
   break;
  case "link" :
   itemLink[itemNum] = itemNodesFolder[j].childNodes[0].nodeValue;
   break;
  case "description" :
   //trace(itemNodesFolder[j].childNodes[0].nodeValue);
   itemDescription[itemNum] = itemNodesFolder[j].childNodes[0].nodeValue;
   break;
  }
 }
 itemNum++;
}
//----预加载XML----
function loadingXML() {
 if (myXML.loaded) {
  perseXML();
  play();
  delete this.onEnterFrame;
 } else {
  XMLpercent = Math.floor(myXML.getBytesLoaded()/myXML.getBytesTotal()*100);
  if (isNaN(XMLpercent)) {
   XMLLoading = "CONNECTING XML...";
   XMLpercent = "0%";
  } else {
   XMLLoading = "LOADING XML...";
   XMLpercent += "%";
  }
  //XML载入进度
 }
}