RSS feed reader - tearing my hair out

Discussion in 'Classic ASP' started by cirrus, Sep 25, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. 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

    <%
    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;output=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; ""
    strhtml = strhtml &amp; "<strong>Line:</strong> " &amp; objXML.parseError.line &amp; ""
    strhtml = strhtml &amp; "<strong>Text:</strong> " &amp; Server.HTMLEncode(objXML.parseError.srcText) &amp; ""


    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>"
    strHTML = strHTML &amp; objItemlist(i).childNodes(3).text &amp; ""
    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


    <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...mp;q=young+drivers+learner+location:uk</link>
    <language>en</language>
    <webMaster>[email protected]</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?s...id=0&amp;amp;ei=69b3RorqLZr40QGb1MWdDw</link>
    <guid isPermaLink="false">http://iccroydon.icnetwork.co.uk/ne...44&amp;amp;siteid=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?s...i=69b3RorqLZr40QGb1MWdDw&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




    <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...mp;q=young+drivers+learner+location:uk</link>
    <language>en</language>
    <webMaster>[email protected]</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>
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page