An Ajax Rss feed reader

Ajax (Asynchronous Javascript And Xml)
I hopemost of you guys know what Ajax (some people say its AJAX) is all about. Ajax is nothing but a way to make website more fast & dynamic by minimizing the amount of request/response data. This is achieved with the help of JavaScript (more precisely we can say, using XmlHttpRequest).

JavaScript:

// Initializing the url connection 
// Connecting to server URL 
// Eg: getFeed.jsp?feedUrl=www.mywebsite.com/feeds.xml 
function http_initDataTransfer(url)   
{ 
 if(connObj == null) 
 { 
  connObj = http_getHttpConnector(); 
  if(connObj != null) 
  { 
     http_setConnectionObject(connObj); 
  } 
  else 
  { 
     ui_showErrorMessage("No Browser Support"); 
     return; 
  } 
 }  

 connObj.open("GET", url); 
 connObj.onReadyStateChange = http_handleStateChange; 
 connObj.send(null);  
} 
// Creating browser dependent XMLHttpTequest object 
function http_getHttpConnector()   
{ 
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}  // MS IE 
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}  // MS IE 
   try { return new XMLHttpRequest(); } catch(e) {}      // Others 
   return (null); 
}
// Connection state change handler 
function http_handleStateChange()  
{ 
  if (connObj.readyState == 4) 
  { 
    if (connObj.status == 200) 
    { 
      var tmpFeedData = connObj.responseText; 
      if(tmpFeedData != null) 
        // Update the view - User defined 
        ui_updateFeed(tmpFeedData);  

      else 
        // Show error message - User defined 
        ui_showErrorMessage("Response Error"); 
    } 
    else 
      ui_showErrorMessage("Network Error"); 
  } 
}

RSS (Really Simple Syndication)
RSS is way to publish frequently changing contents like blog posts, news updates, stock quotes & things like that. An RSS document, which is called a “feed,” “web feed,” or “channel,” contains either a summary of content from an associated web site or the full text. RSS formats are specified using XML, a generic specification for the creation of data formats.

I have already posted a SAX based RSS feed parser here. Use this class to get the feed data from the URL and send it as the response in the form of JSON or some other application dependent format.

Use org.json Java API to enable JSON support. Get org.json

Advertisements