PDA

View Full Version : RSS feed reader - tearing my hair out


cirrus
09-25-2007, 03:29 AM
I have code that works fine provided the feed contains all the correct elements. The code is a server side include that sits in a Div on the home page of my site.

Occasionally Google puts out a feed with no new items. When that happens this code fails and the page crashes with an object required error on line 31 (first iteration through the item list). I have been on this for a couple of days but am way out of my depth with MSXML.

Basically I need a way to test whether there are any <item> elements in the RSS feed before it crashes the page.

All help and advice gratefully received.

Steve D

This is the feed reader code
[b]
<%
Dim objXML
Dim objItemList
Dim objItem
Dim strHTML
dim loadsuccess
dim i

Set objXML = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
objXML.async = False
objXML.setProperty "ServerHTTPRequest", True

loadsuccess = objXML.Load("http://news.google.co.uk/news?svnum=10&amp;oe=UTF-8&amp;hl=en&amp;tab=wn&amp;ie=UTF-8&amp;scoring=n&amp;q=young+drivers+learner+location:uk&amp;ou tput=rss")
' BBC Feed childNodes: 0=title, 1=link, 2=link 3=timestamp 4=description
' google feed childnodes:

If objXML.parseError.errorCode <> 0 Then

strhtml = strhtml &amp; "<strong>Error:</strong> " &amp; objXML.parseError.reason &amp; "[b]"
strhtml = strhtml &amp; "<strong>Line:</strong> " &amp; objXML.parseError.line &amp; "[b]"
strhtml = strhtml &amp; "<strong>Text:</strong> " &amp; Server.HTMLEncode(objXML.parseError.srcText) &amp; "[b]"


elseif loadsuccess then

Set objItemList = objXML.getElementsByTagName("item")

for i = 0 to 9

strHTML = strHTML &amp; "<a href="""&amp; objItemlist(i).childNodes(1).text &amp; """ target=""_blank"">"
strHTML = strHTML &amp; objItemlist(i).childNodes(0).text &amp; "</a>[b]"
strHTML = strHTML &amp; objItemlist(i).childNodes(3).text &amp; "[b]"
strHTML = strHTML &amp; "<hr width=""50%"" align=""center"" />"

next
Set objItemList = Nothing
Set objXML = Nothing

else
strhtml = "News feed temporarily unavailable"
strHTML = strHTML &amp; "<hr width=""50%"" align=""center"" />"

End If
%>
</BLOCKQUOTE>
It works fine with this feed

[b]
<rss version="2.0">
<channel>
<generator>NFE/1.0</generator>
<title>young drivers learner location:uk - Google News</title>
<link>http://news.google.co.uk/news?svnum=10&amp;amp;oe=UTF-8&amp;amp;hl=en&amp;amp;tab=wn&amp;amp;ie=UTF-8&amp;amp;scoring=n&amp;amp;q=young+drivers+learner+locati on:uk</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&amp;amp;copy;2007 Google</copyright>
<pubDate>Mon, 24 Sep 2007 15:25:31 GMT</pubDate>
<lastBuildDate>Mon, 24 Sep 2007 15:25:31 GMT</lastBuildDate>
<image>
<title>young drivers learner location:uk - Google News</title>
<url>http://news.google.com/intl/en_uk/images/news_res.gif</url>
<link>http://news.google.co.uk/</link>
</image>
<item>
<title>Boy racers defy the police - ic Croydon</title>
<link>http://news.google.co.uk/news/url?sa=T&amp;amp;ct=uk/0-0&amp;amp;fd=R&amp;amp;url=http://iccroydon.icnetwork.co.uk/news/headlines/tm_headline%3Dboy-racers-defy-the-police%26method%3Dfull%26objectid%3D19820944%26sit eid%3D53340-name_page.html&amp;amp;cid=0&amp;amp;ei=69b3RorqLZr40QGb1M WdDw</link>
<guid isPermaLink="false">http://iccroydon.icnetwork.co.uk/news/headlines/tm_headline=boy-racers-defy-the-police&amp;amp;method=full&amp;amp;objectid=19820944&amp;amp;s iteid=53340-name_page.html</guid>
<pubDate>Fri, 21 Sep 2007 09:40:47 GMT</pubDate>
<description>&amp;lt;table border=0 width= valign=top cellpadding=2 cellspacing=7&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td valign=top class=j&amp;gt;&amp;lt;br&amp;gt;&amp;lt;div class=lh&amp;gt;&amp;lt;a href=&amp;quot;http://news.google.co.uk/news/url?sa=T&amp;amp;ct=uk/0-0&amp;amp;fd=R&amp;amp;url=http://iccroydon.icnetwork.co.uk/news/headlines/tm_headline%3Dboy-racers-defy-the-police%26method%3Dfull%26objectid%3D19820944%26sit eid%3D53340-name_page.html&amp;amp;cid=0&amp;amp;ei=69b3RorqLZr40QGb1M WdDw&amp;quot;&amp;gt;Boy racers defy the police&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;&amp;lt;font size=-1&amp;gt;&amp;lt;font color=#6f6f6f&amp;gt;ic Croydon,&amp;amp;nbsp;UK&amp;amp;nbsp;-&amp;lt;/font&amp;gt; &amp;lt;nobr&amp;gt;21 Sep 2007&amp;lt;/nobr&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;font size=-1&amp;gt;by Ross lLdbetter POLICE have been insisting for months they are clamping down on the boy racers and bikers making life a misery for residents around &amp;lt;b&amp;gt;...&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;</description>
</item>
<description>young drivers learner location:uk - Google News</description>
</channel>
</rss>
</BLOCKQUOTE>

This is a feed that will crash it

[b]


<rss version="2.0">
<channel>
<generator>NFE/1.0</generator>
<title>young drivers learner location:uk - Google News</title>
<link>http://news.google.co.uk/news?svnum=10&amp;amp;oe=UTF-8&amp;amp;hl=en&amp;amp;tab=wn&amp;amp;ie=UTF-8&amp;amp;scoring=n&amp;amp;q=young+drivers+learner+locati on:uk</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&amp;amp;copy;2007 Google</copyright>
<pubDate>Mon, 24 Sep 2007 14:31:24 GMT</pubDate>
<lastBuildDate>Mon, 24 Sep 2007 14:31:24 GMT</lastBuildDate>
<image>
<title>young drivers learner location:uk - Google News</title>
<url>http://news.google.com/intl/en_uk/images/news_res.gif</url>
<link>http://news.google.co.uk/</link>
</image>
<description>young drivers learner location:uk - Google News</description>
</channel>
</rss>
</BLOCKQUOTE>