JavaScript JS:解析RSS Feed

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript JS:解析RSS Feed相关的知识,希望对你有一定的参考价值。

function SendAjax(url, callbackFunction) {
   if (window.XMLHttpRequest) {
      var request = new XMLHttpRequest();
   } else {
      var request = new ActiveXObject("Microsoft.XMLHTTP");
   }
 
   request.open("POST", url, true);
   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
 
   request.onreadystatechange = function() {
      if (request.readyState == 4 && request.status == 200) {
         if (request.responseText) {
            ReceiveAjax(request.responseText, callbackFunction);
         }
      }
   }

   request.send(null);
}

function ReceiveAjax(response, callbackFunction) {
   if (window.ActiveXObject) {
      var doc = new ActiveXObject("Microsoft.XMLDOM");
      doc.async = "false";
      doc.loadXML(response);
   } else {
      var parser = new DOMParser();
      var doc = parser.parseFromString(response,"text/xml");
   }

   callbackFunction(doc.documentElement);
}

function ValueFromTagName(item, tagname) {
   var val = item.getElementsByTagName(tagname);
   return val[0].firstChild.nodeValue;
}

function ParseData(data) {
   var items = data.getElementsByTagName('item');
   var output = '<ul>';

   for (var i = 0; i < items.length; ++i) {
      var title = ValueFromTagName(items[i], 'title');
      var link = ValueFromTagName(items[i], 'link');

      output += '<li><strong><a href ="' + link + '">' + title + '</strong> ' + '</li>';
   }

   output += '</ul>';

   var RSSOutput = document.getElementById('RSSOutput');
   	   RSSOutput.innerHTML = output;
}

function LoadFeed( url ) {
   var GetFeed = url;
   SendAjax('getfeed.php?url=' + escape(GetFeed.value), ParseData);
}
LoadFeed( "http://del.icio.us/rss/twelvetone" );

以上是关于JavaScript JS:解析RSS Feed的主要内容,如果未能解决你的问题,请参考以下文章

如何在 iOS 上使用 Swift 将 1 个以上的 RSS Feed 解析并合并为一个 Feed

javascript Google Analytics RSS Feed跟踪

从rss feed获取新项目

[UWP]涨姿势UWP源码——RSS feed的获取和解析

当rss feed改变php时如何播放声音

在Ruby / Rails中解析Atom和RSS?