SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript and Rss Feeds

    Hello to all
    Im fairly new to javascript and Ive been working on an assignment all day but now im stuck.
    Im trying to set up a table that when a option is selected it displays a rss feed below it. Ive set up an xml rss and the script seems to read it ok but when displayed it only shows the last item of the rss. Here is my code
    Code:
    function stateChanged()
    {
    	if (xmlHttp.readyState == 4 )
    	{
    		alert("test 1");
    		var node = xmlHttp.responseXML;
    		var newsItem = node.getElementsByTagName("item");
    		alert("Item length " + newsItem.length )
    		document.getElementById("print_rss").innerHTML = "";
    		for (var i=0; i<newsItem.length; i++){
    			
    			document.getElementById("print_rss").innerHTML = newsItem[i].getElementsByTagName("title")[i].childNodes[i].nodeValue;
    			}
    	}
    I was trying to use appendChild instead but no luck. Any ideas on where im going wrong?

    My second question is how would I modify my code to allow the user to chose which RSS feed they wanted to view? Here is my current code
    Code:
    function showRSS()
    {
    	xmlHttp = GetXmlHttpObject();
    	
    	if (xmlHttp == null) {
    		alert("Browser does not support HTTP Request");
    		return;
    	}
    	
    	var url = "rte_rss.php?id=" +"http://www.rte.ie/rss/sport.xml";
    	
    	xmlHttp.open("GET", "sport.xml", true);
    	xmlHttp.send(null);
    	xmlHttp.onreadystatechange = stateChanged;
    	
    }
    I realise im asking a lot and I apologise. Its just Ive been working on this for 2 days now with very little luck. Any help or hints would be greatly appreciated.
    Thanks in advance.

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem to be rewriting the innerHtml on each iteration, rather than adding to it.
    Code:
    // Should the equals in
    document.getElementById("print_rss").innerHTML = newsItem[i].getElementsByTagName("title")[i].childNodes[i].nodeValue;
    
    // be changed to += ?
    document.getElementById("print_rss").innerHTML += newsItem[i].getElementsByTagName("title")[i].childNodes[i].nodeValue;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •