Total members 11894 |It is currently Thu Nov 21, 2024 10:33 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





In this small article we are reading RSS using JavaScript code, RSS stands for (Rich Site Summary), RSS has its own format for providing information about the latest websites content updates, such as blogs/forums/wikis articles, images and videos. Many versions of RSS have many developed, currently we see the format of RSS 2.0 at following XML format :
Code:



<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>RSS Feeds Title</title>
        <description>Feeds by RSS example</description>
        <link>http://www.codemiles.com/rss.html</link>
        <lastBuildDate>Mon, 06 Sep 2012 00:02:00 +0000 </lastBuildDate>
        <pubDate>Mon, 06 Sep 2012 11:13:00 +0000 </pubDate>
        <ttl>1800</ttl>
 
        <item>
                <title>RSS feeds parsing</title>
                <description>How to parse RSS in javascript....</description>
                <link>http://www.codemiles.com/javascriptRSS.html</link>
                <guid>unique string per item</guid>
                <pubDate>Mon, 06 Sep 2012 11:11:00 +0000 </pubDate>
        </item>
 
</channel>
</rss>


In this article we parse RSS XML using JavaScript, we use the Dojo free toolkit for javascript/ajax applications :
Code:

<script type="text/javascript">
dojo.addOnLoad(function() {
      var divID = "divShow";
      
      
// Parse Rss Feed
      dojo.xhrGet({
         url: "rssFile.xml",
         preventCache: true,
         handleAs: "xml",
         load: function(xmlDoc, ioArgs){         
             var i 
= 0;
             var htmlReturn = "";
          
             var mainNode 
= xmlDoc.getElementsByTagName("channel").item(0);
         
             if 
(mainNode == null) {
                 console.debug("Error in RSS format ...");                           
                 return
;
             }
         
             var NumberOfItems 
= mainNode.getElementsByTagName("item").length;
             
             for 
(= 0; i < NumberOfItems; ++i) {
                var entry = mainNode.getElementsByTagName('item').item(i);
                 
                var title 
= entry.getElementsByTagName('title').item(0).firstChild.data;
                 var published = entry.getElementsByTagName('pubDate').item(0).firstChild.data;            
                 var description 
= entry.getElementsByTagName('description').item(0).firstChild.data;
                 var link = entry.getElementsByTagName('link').item(0).firstChild.data;
                 
                htmlReturn 
+= '<hr><p><a target="_blank" href="' + link +'">' + title + '</a><br/>' + 
                          
'<span class="smaller">' + published + '</span><br/>' + 
                          description 
+
                          '</p>';
             }
                 
             document
.getElementById(divID).innerHTML = htmlReturn;             
       
},
       error: function(error, ioArgs){             
             dojo
.byId(divID).innerHTML = "Failed To Load RSS Feeds";
             console.debug("failed xhrGet for Rss URL: ", error, ioArgs);                   
         
}      
    
});
});
    
</script>

<div id="divShow"></div>


As you can see the code ,we read each items (node) and its children (Title,Description ... etc) .

For more information about RSS
Code:
http://en.wikipedia.org/wiki/RSS


For more information about DOJO toolkit :
Code:
http://en.wikipedia.org/wiki/Dojo_Toolkit




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Parsing and Reading RSS feeds
 Parsing ATOM feeds     -  
 Load RSS feeds and parse it with JQuery     -  
 Parsing a Processing Instruction     -  
 Latest XML parsing/memory usage benchmark     -  
 Reading the all file in php     -  
 Reading file with integers     -  
 Multithreaded File Reading     -  
 help reading greyscaled image !     -  
 Java Object Reading     -  
 Reading a Specific Character in php     -  



Topic Tags

JavaScript RSS
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com