Hi I'm new to the development world and have bumped into a tough problem for myself.
I'm attempting to display external RSS feeds on my site using AJAX. The 'title' and 'link' tags from the XML file appear on my page without any problem. However, unlike the 'title' and 'link' tags, some of the 'description' tags contain HTML.
RSS link: Jonathon's BlogEntry at 1Up.com
This seems to be an issue when I'm trying to display the content within the description tags.
As you can see, I embarassingly tried enclosing the variable newtext2 in CDATA tags to no avail. Since I do not directly have access to this RSS file (other than asking my friend if I can edit it), is there a way for me to display the HTML content within the 'description' tags strictly via JavaScript?Code:function getXMLHTTPRequest() { try { req = new XMLHttpRequest(); /* e.g. Firefox */ } catch(e) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); /* some versions IE */ } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); /* some versions IE */ } catch (E) { req = false; } } } return req; } var ro2 = getXMLHTTPRequest(); function getGRblogRSS() { var mygrurl = 'rssfeedproxy.php?blogfeed='; var mygrfeed = 'http://www.1up.com/journalRSS?publicUserId=5641199'; mygrRand = parseInt(Math.random()*999999999999999); // cache buster var modgrurl = mygrurl+escape(mygrfeed)+"&rand="+mygrRand; ro2.open("GET", modgrurl, true); ro2.onreadystatechange = useBlogResponse; ro2.send(null); } function useBlogResponse() { if (ro2.readyState == 4) { if(ro2.status == 200) { // first remove the childnodes presently in the DM while (document.getElementById('grblognews').hasChildNodes()) { document.getElementById('grblognews').removeChild(document.getElementById('grblognews').firstChild); } var titleNodes = ro2.responseXML.getElementsByTagName("title"); var descriptionNodes= ro2.responseXML.getElementsByTagName("description"); var linkNodes = ro2.responseXML.getElementsByTagName("link"); for(var i =2;i<7;i++) { var newtext = document.createTextNode(titleNodes[i].childNodes[0].nodeValue); var newpara = document.createElement('p'); newpara.className = "grblogtitle"; var para = document.getElementById('grblognews').appendChild(newpara); newpara.appendChild(newtext); var linkstring = linkNodes[i].childNodes[0].nodeValue; var newpara3 = document.createElement('p'); newpara3.className = "grbloglink"; var newsdiv = document.getElementById('grblognews'); newpara3.innerHTML = '<a href="'+linkstring+'">'+linkstring+'</a>'; var para3 = newsdiv.appendChild(newpara3); var newtext2= document.createTextNode(descriptionNodes[i].childNodes[0].nodeValue); var newnontagtext= '<![CDATA['+newtext2+']]>'; var newpara2 = document.createElement('p'); newpara2.className = "grblogdescription"; var para2 = document.getElementById('grblognews').appendChild(newpara2); newpara2.appendChild(newnontagtext); } } } }


Reply With Quote
Bookmarks