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&oe=UTF-8&hl=en&tab=wn&ie=UTF-8&scoring=n&q=young+drivers+learner+location:uk&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 & "<strong>Error:</strong> " & objXML.parseError.reason & "[b]"
strhtml = strhtml & "<strong>Line:</strong> " & objXML.parseError.line & "[b]"
strhtml = strhtml & "<strong>Text:</strong> " & Server.HTMLEncode(objXML.parseError.srcText) & "[b]"
elseif loadsuccess then
Set objItemList = objXML.getElementsByTagName("item")
for i = 0 to 9
strHTML = strHTML & "<a href="""& objItemlist(i).childNodes(1).text & """ target=""_blank"">"
strHTML = strHTML & objItemlist(i).childNodes(0).text & "</a>[b]"
strHTML = strHTML & objItemlist(i).childNodes(3).text & "[b]"
strHTML = strHTML & "<hr width=""50%"" align=""center"" />"
next
Set objItemList = Nothing
Set objXML = Nothing
else
strhtml = "News feed temporarily unavailable"
strHTML = strHTML & "<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;oe=UTF-8&amp;hl=en&amp;tab=wn&amp;ie=UTF-8&amp;scoring=n&amp;q=young+drivers+learner+locati on:uk</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&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;ct=uk/0-0&amp;fd=R&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;cid=0&amp;ei=69b3RorqLZr40QGb1M WdDw</link>
<guid isPermaLink="false">http://iccroydon.icnetwork.co.uk/news/headlines/tm_headline=boy-racers-defy-the-police&amp;method=full&amp;objectid=19820944&amp;s iteid=53340-name_page.html</guid>
<pubDate>Fri, 21 Sep 2007 09:40:47 GMT</pubDate>
<description>&lt;table border=0 width= valign=top cellpadding=2 cellspacing=7&gt;&lt;tr&gt;&lt;td valign=top class=j&gt;&lt;br&gt;&lt;div class=lh&gt;&lt;a href=&quot;http://news.google.co.uk/news/url?sa=T&amp;ct=uk/0-0&amp;fd=R&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;cid=0&amp;ei=69b3RorqLZr40QGb1M WdDw&quot;&gt;Boy racers defy the police&lt;/a&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;font color=#6f6f6f&gt;ic Croydon,&amp;nbsp;UK&amp;nbsp;-&lt;/font&gt; &lt;nobr&gt;21 Sep 2007&lt;/nobr&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&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 &lt;b&gt;...&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&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;oe=UTF-8&amp;hl=en&amp;tab=wn&amp;ie=UTF-8&amp;scoring=n&amp;q=young+drivers+learner+locati on:uk</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&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>
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&oe=UTF-8&hl=en&tab=wn&ie=UTF-8&scoring=n&q=young+drivers+learner+location:uk&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 & "<strong>Error:</strong> " & objXML.parseError.reason & "[b]"
strhtml = strhtml & "<strong>Line:</strong> " & objXML.parseError.line & "[b]"
strhtml = strhtml & "<strong>Text:</strong> " & Server.HTMLEncode(objXML.parseError.srcText) & "[b]"
elseif loadsuccess then
Set objItemList = objXML.getElementsByTagName("item")
for i = 0 to 9
strHTML = strHTML & "<a href="""& objItemlist(i).childNodes(1).text & """ target=""_blank"">"
strHTML = strHTML & objItemlist(i).childNodes(0).text & "</a>[b]"
strHTML = strHTML & objItemlist(i).childNodes(3).text & "[b]"
strHTML = strHTML & "<hr width=""50%"" align=""center"" />"
next
Set objItemList = Nothing
Set objXML = Nothing
else
strhtml = "News feed temporarily unavailable"
strHTML = strHTML & "<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;oe=UTF-8&amp;hl=en&amp;tab=wn&amp;ie=UTF-8&amp;scoring=n&amp;q=young+drivers+learner+locati on:uk</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&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;ct=uk/0-0&amp;fd=R&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;cid=0&amp;ei=69b3RorqLZr40QGb1M WdDw</link>
<guid isPermaLink="false">http://iccroydon.icnetwork.co.uk/news/headlines/tm_headline=boy-racers-defy-the-police&amp;method=full&amp;objectid=19820944&amp;s iteid=53340-name_page.html</guid>
<pubDate>Fri, 21 Sep 2007 09:40:47 GMT</pubDate>
<description>&lt;table border=0 width= valign=top cellpadding=2 cellspacing=7&gt;&lt;tr&gt;&lt;td valign=top class=j&gt;&lt;br&gt;&lt;div class=lh&gt;&lt;a href=&quot;http://news.google.co.uk/news/url?sa=T&amp;ct=uk/0-0&amp;fd=R&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;cid=0&amp;ei=69b3RorqLZr40QGb1M WdDw&quot;&gt;Boy racers defy the police&lt;/a&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;font color=#6f6f6f&gt;ic Croydon,&amp;nbsp;UK&amp;nbsp;-&lt;/font&gt; &lt;nobr&gt;21 Sep 2007&lt;/nobr&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&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 &lt;b&gt;...&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&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;oe=UTF-8&amp;hl=en&amp;tab=wn&amp;ie=UTF-8&amp;scoring=n&amp;q=young+drivers+learner+locati on:uk</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&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>