Wolverine68 Posted July 5, 2009 Share Posted July 5, 2009 Trying to extract and display data from an xml news feed.Getting "object expected" error on line 88. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="prototype.js" type="text/javascript"> <script src="scriptaculous.js" type="text/javascript"> <title>News Feeds</title> <style type="text/css"> .showIt { font-size: 14pt; color: green; font-family: Arial, Tahoma, Verdana; border: thick solid; padding: 10px; } b { font-size: 16pt; color:#000000; } </style> <script type="text/javascript" language="javascript"> <!--The object detection code --> var req = false; // Is there support for native XHR object?: IE7+, Firefox, Safari, Opera if (window.XMLHttpRequest) { req = new XMLHttpRequest(); //create an XMLHttpRequest object } else if (window.ActiveXObject) //check for Version 6 { req = new ActiveXObject('MSXML2.XMLHTTP.6.0'); //create an ActiveX XMLHTTP component } if (!req) { req = new ActiveXObject('MSXML2.XMLHTTP'); //fallback to version 3 } function getFeed() { if (req) { //Request feed data to be retrieved from the server req.onreadystatechange = function() { if (req.readyState == 4 && req.status == 200) { var response = req.responseXML; readXML(response); } } req.open("GET", "SportsNewsFeed.xml", true); req.send(null); } } function readXML(response) { var myResponse = response.documentElement; var myFeed = myResponse.getElementsByTagName("channel"); var place = document.getElementById("showIt"); for (var i=0; i < myFeed.length; i++) { place.innerHTML += myFeed[i].getElementsByTagName("title")[0].firstChild.nodeValue + ":" ; place.innerHTML += myFeed[i].getElementsByTagName("link")[0].firstChild.nodeValue + 'onmouseover="Effect.Puff"' + "<br><br>"; } } //--> </script> </head> <body onload="getFeed()"> <p id="showIt" class="showIt"></p> </body> </html> XML file: <?xml version="1.0" encoding="utf-8" ?> <rss version="2.0"> <channel> <title>Sports News Feed Index</title> <link>http://sports.espn.go.com/espn/rss/index</link> <description>Keep up to date on the latest sports news</description> <language>en</language> <item> <title>NFL Headlines</title> <link>http://sports.espn.go.com/espn/rss/nfl/news</link> <description>The latest pro football news</description> </item> <item> <title>NBA Headlines</title> <link>http://sports.espn.go.com/espn/rss/nba/news</link> <description>The latest pro basketball news</description> </item> <item> <title>MLB Headlines</title> <link>http://sports.espn.go.com/espn/rss/mlb/news</link> <description>The latest Major League Baseball news</description> </item> <item> <title>NHL Headlines</title> <link>http://sports.espn.go.com/espn/rss/nhl/news</link> <description>The latest pro hockey news</description> </item> </channel> </rss> Quote Link to comment Share on other sites More sharing options...
haku Posted July 5, 2009 Share Posted July 5, 2009 And line 88 is? Quote Link to comment Share on other sites More sharing options...
Wolverine68 Posted July 5, 2009 Author Share Posted July 5, 2009 Line 88: <body onload="getFeed()"> Quote Link to comment Share on other sites More sharing options...
Wolverine68 Posted July 8, 2009 Author Share Posted July 8, 2009 Ok, got it closer to working. It loops through and displays each of the links. However, the links show on the HTML page as plain text rather than live url links. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="prototype.js" type="text/javascript"></script> <script src="scriptaculous.js" type="text/javascript"></script> <title>News Feeds</title> <style type="text/css"> .showIt { font-size: 14pt; color: green; font-family: Arial, Tahoma, Verdana; border: thick solid; padding: 10px; } b { font-size: 16pt; color:#000000; } </style> <script type="text/javascript" language="javascript"> <!--The object detection code --> var req = false; // Is there support for native XHR object?: IE7+, Firefox, Safari, Opera if (window.XMLHttpRequest) { req = new XMLHttpRequest(); //create an XMLHttpRequest object } else if (window.ActiveXObject) //check for Version 6 { req = new ActiveXObject('MSXML2.XMLHTTP.6.0'); //create an ActiveX XMLHTTP component } if (!req) { req = new ActiveXObject('MSXML2.XMLHTTP'); //fallback to version 3 } function getFeed() { if (req) { //Request feed data to be retrieved from the server req.onreadystatechange = function() { if (req.readyState == 4 && req.status == 200) { var response = req.responseXML; readXML(response); } } req.open("GET", "SportsNewsFeed.xml", true); req.send(null); } } function readXML(response) { var myResponse = response.documentElement; var myFeed = myResponse.getElementsByTagName("item"); var place = document.getElementById("showIt"); for (var i=0; i < myFeed.length; i++) { place.innerHTML += myFeed[i].getElementsByTagName("title")[0].firstChild.nodeValue + ":" ; place.innerHTML += myFeed[i].getElementsByTagName("link")[0].firstChild.nodeValue + "<br><br>"; } } //--> </script> </head> <body onLoad="getFeed()"> <p id="showIt" class="showIt"></p> </body> </html> XML file: <?xml version="1.0" encoding="utf-8" ?> <rss version="2.0"> <channel> <item> <title>NFL Headlines</title> <link>http://sports.espn.go.com/espn/rss/nfl/news</link> <description>The latest pro football news</description> </item> <item> <title>NBA Headlines</title> <link>http://sports.espn.go.com/espn/rss/nba/news</link> <description>The latest pro basketball news</description> </item> <item> <title>MLB Headlines</title> <link>http://sports.espn.go.com/espn/rss/mlb/news</link> <description>The latest Major League Baseball news</description> </item> <item> <title>NHL Headlines</title> <link>http://sports.espn.go.com/espn/rss/nhl/news</link> <description>The latest pro hockey news</description> </item> </channel> </rss> Quote Link to comment Share on other sites More sharing options...
haku Posted July 9, 2009 Share Posted July 9, 2009 That's because you are just passing the link as text. You need to wrap it in an anchor tag (<a>). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.