• Hey! Don't you want go to home to see my new posts?

Loading a RSS XML feed just using JavaSript

Posted by Micox - Náiron J. C. G..

March 13, 2007

Continuating the post Manipulating XML using JavaScript, now a util example of XML + JavaScript: Loading a RSS XML feed.

1) Manipulating XML using JavaScript

See my previous small tutorial about XML + JavaScript to understend the function above.

2) Making the function to read RSS data

Put the JavaScript function above in your html document or in a ".js" file (and include in your document).

function xmlMicoxRSS(xmlNode){
 //by Micox: http://elmicoxcodes.blogspot.com
 var retorno = "";
 var objNodeList = xmlNode.getElementsByTagName("item")
 for(var i=0;i<objNodeList.length;i++){
  var strTitulo = ""
  var strURL = ""
  var strDescr = ""
  var objNode = objNodeList[i];
  if(objNode.nodeType == 1){//ignore white spaces
   for(var j=0;j<objNode.childNodes.length;j++){
    var objNode2 = objNode.childNodes[j];
    if(objNode2.nodeType == 1){//ignore white spaces
     switch (objNode2.nodeName) {
      case "title": 
       //alert(objNode.childNodes[j].firstChild.nodevalue);
       strTitulo = objNode2.firstChild.nodeValue; 
       break;
      case "link": 
       strURL = objNode2.firstChild.nodeValue; 
       break;
      case "description": 
       strDescr = objNode2.firstChild.nodeValue; 
       break;
     }
    }
   }
   retorno += " <li><a href='" + strURL + "'>" + strTitulo + "</a><br />" + strDescr + "</li>\n";
  }
 }
 retorno = "<ul>\n" + retorno + "</ul>";
 return retorno;
}

3) Now, put the return to your DIV

First, call the function xmlMicoxLoader (previous post) and give to div the return of function xmlMicoxRSS.

xml = xmlMicoxLoader("rss.xml"); //load xml
document.getElementById(div_alvo).innerHTML = xmlMicoxRSS(xml); //list rss

Important: JavaScript just load file in your domain for security reasons.

Another example of XML + Javascript: Dynamic Graphs with Ajax and XML.

Bugs, tests and doubts, comment here :) Sorry my bad english.

Labels: , , , ,

Sorry my bad english :) .
Type a comment! The finger dont fall (9 comments).

Add to Del.icio.usDel.icio.us Digg!

celulares; mp3, mp4, mp5, mp7; playstation; Libros

Concursos públicos

9 Comments:

Anonymous Yash said... June 16, 2007 3:32 AM  
Nice info..thank you for your work
Blogger Zibri said... August 8, 2008 7:27 PM  
I need this code to work inside a blogger page and get XML from another site.

I tried everything but I get access denied.

But blogger uses a similar way to get external feeds.

Does anybody know how does blogger do it ?
Blogger Micox - Náiron J. C. G. said... August 9, 2008 5:02 AM  
Hi zibri,

by security reasons, browsers dont give access to javascript access external domains. becouse of this, that you receive 'access denied' message.

the blogger effect uses server-side programation. In server-side programation (asp, php, jsp, etc) you will get another site.

thanks.
Anonymous Anonymous said... November 3, 2009 3:00 PM  
miley cyrus nude miley cyrus nude miley cyrus nude
Anonymous Anonymous said... November 8, 2009 1:28 PM  
hi i am Henry i have airplane WOW?
http://henryairplane.atwebpages.com/what-does-an-airplane-ticket-look-like.html
Anonymous Anonymous said... November 10, 2009 9:56 PM  
порно фото малолеток на пляже http://free-3x.com/ развлечения тинейджеров фильм free-3x.com/ студенты отдыхают видео [url=http://free-3x.com/]free-3x.com[/url]
Anonymous Anonymous said... November 11, 2009 3:20 AM  
Discount RX Pharmacy - Cialis, Viagra, Levitra, Tamiflu. Get Cheap Medication online. Buy Pills Central.
[url=http://buypillscentral.com/buy-generic-tamiflu-online.html]Get Cheap Viagra, Cialis, Levitra, Tamiflu[/url]. prescription generic pills. Cheap medications pharmacy
Anonymous Anonymous said... November 15, 2009 10:57 PM  
For many years Buy Cialis Detract from Dispensary has been recognizable among paramount online pharmaceutics suppliers and customers all over Cheap Discount Cialis Pharmacy On-line the world.
Anonymous Anonymous said... November 27, 2009 12:58 PM  
760 6
728 7
448 3
61 7
318 5
659 9
146 6
598 3

Write your comment.

Links to this post:

<< Go back to Home Page to see new posts.

Micox Codes - Some Rights Reserved - Creative Commons