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

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





In this article we show a small example for parsing atom feeds using javascript code. Atom format was developed as an alternative to RSS. The innovation of Atom design was based on the believe that RSS had limitations and flaws—such as lack of on-going innovation and its necessity to remain backward compatible. Following is an example of ATOM format :
Code:

<?xml version="1.0" encoding="utf-8"?>
 
<feed xmlns="http://www.w3.org/2005/Atom">
 
        <title>Title here (Feed Title)</title>
        <subtitle>If there a subtitle</subtitle>
        <link href="http://codemiles.com/feed/" rel="self" />
        <link href="http://codemiles.com/" />
        <id>urn:uuid:5ce14e53-a349-1455-c433-4305315cccc6</id>
        <updated>2012-11-11T18:10:01Z</updated>
 
 
        <entry>
                <title>Parsing ATOM Feeds</title>
                <link href="http://codemiles.com/2012/11/11/atom03" />
                <link rel="alternate" type="text/html" href="http://codemiles.com/2012/11/11/atom03.html"/>
                <link rel="edit" href="http://codemiles.com/2012/11/11/atom03/edit"/>
                <id>urn:uuid:14444ccc-13ec-3cc2-142c-13ac4cec5c3c</id>
                <updated>2012-11-11T18:10:02Z</updated>
                <summary>Some text.</summary>
                <author>
                      <name>msi_333</name>
                      <email>[email protected]</email>
                </author>
        </entry>
 
</feed>


Following is an code snippet for parsing XML ATOM format using JavaScript ( Using Dojo JavaScript Toolkit) :
Code:

<script type="text/javascript">
dojo.addOnLoad(function() {
      var htmlDivID = "contentDiv";
      
      
// Parse ATOM feed
      dojo.xhrGet({
         url: "myFeed.xml",
         preventCache: true,
         handleAs: "xml",
          load: function(xmlDoc, ioArgs){         
             var i 
= 0;
             var htmlOutputContent = "";
          
             var node 
= xmlDoc.getElementsByTagName("feed").item(0);
         
             if 
(node == null) {
                 console.debug("ERROR: Error in parsing ATOM Feeds XML format.");                     
                 return
;
             }
         
             var NumOfFeedsEntry 
= node.getElementsByTagName("entry").length;
         
             for 
(= 0; i < NumOfFeedsEntry; ++i) {
                var entry = node.getElementsByTagName('entry').item(i);
                 
                var title 
= entry.getElementsByTagName('title').item(0).firstChild.data;
                 var published = entry.getElementsByTagName('published').item(0).firstChild.data;            
                 var summary 
= entry.getElementsByTagName('summary').item(0).firstChild.data;
                 var link = entry.getElementsByTagName('link').item(0).getAttribute("href");
                 
                htmlOutputContent 
+= '<hr><p><a target="_blank" href="' + link +'">' + title + '</a><br/>' + 
                          
'<span class="smaller">' + published + '</span><br/>' + 
                          summary 
+
                          '</p>';
             }
             
             document
.getElementById(htmlDivID).innerHTML = htmlOutputContent;             
         
},
         error: function(error, ioArgs){                 
             dojo
.byId(htmlDivID).innerHTML = "Error In Loading and Parsing The Atom Feeds";
             console.debug("ATOM URL CONTENT PASRING ERROR (DEBUG): ", error, ioArgs);             
         
}
    });
});
    
</script>

<div id="contentDiv"></div>


Dojo is open source toolkit developed to ease the JavaScript\Ajax applications, for more information about Dojo :
Code:
http://en.wikipedia.org/wiki/Atom_%28standard%29




_________________
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 ATOM feeds
 Parsing and Reading RSS feeds     -  
 Load RSS feeds and parse it with JQuery     -  
 Parsing a Processing Instruction     -  
 Latest XML parsing/memory usage benchmark     -  



Topic Tags

JavaScript ATOM
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