0

Implementing a JS script to pull/parse an XML feed and return the contents into an html . Unfortunately, it doesn't seem to be doing so, as nothing but the text (Feed!) between the div tags appears on the page.

function loadRSSFeed(param){
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET",'http://feeds.feedburner.com/engadget/Dnjv',false);
  xmlhttp.send();
  xmlDoc = xmlhttp.responseXML;
  var strBuffer= "";
  strBuffer = strBuffer +"<table border='1'>";
  var x=xmlDoc.getElementsByTagName("item");
  for (i=0;i<x.length;i++){   
        strBuffer = strBuffer +"<tr><td><a href='";
        strBuffer = strBuffer +(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
        strBuffer = strBuffer +"'>";
        strBuffer = strBuffer +(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
        strBuffer = strBuffer +"</a></td></tr><tr><td>";
        strBuffer = strBuffer +(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue.substring(0,180));
        strBuffer = strBuffer + "<a href='";
        strBuffer = strBuffer +(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
        strBuffer = strBuffer +"'>... Read More...</a>";
        strBuffer = strBuffer +"</td></tr>";
        if(i==10){
          break;
        }
    }
  strBuffer = strBuffer +"</table>";
  document.getElementById(param).innerHTML =strBuffer;
}

it is imported like so (successfully): Then called in the body

<body onload ="loadRSSFeed('feeddisplay');">
  <h1>All the news that's fit to render</h1>
  <div id="feeddisplay">Feed!</div>
</body>

But it does not show up! The rest of the page does as it's supposed to...

Thoughts?

2 Answers 2

2

Shouldn't that be XMLHttp*Request*?

Sign up to request clarification or add additional context in comments.

Comments

1

The google feed reader api is more robust and has few more features to handle rss

http://code.google.com/apis/feed/v1/

Also I think onLoad may not be able to find the div ... ? did you try executing the script after the div feed was loaded ... just my 2 cents.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.