I am trying to create an ASP.NET application that
consumes an RSS Newsfeed from Yahoo News
(http://rss.news.yahoo.com/rss/topstories). I keep
getting the following error message, even though my code
seems corect. In fact, when I drop virtually the same
code into a Windows Forms application using VB.NET and
use a Windows Forms datagrid, I get the xml from the
newsfeed without any problem.
Here is the error message:
"The 'META' start tag on line '1' doesn't match the end
tag of 'HEAD' in file
http://rss.news.yahoo.com/rss/topstories'. Line 1,
position 135."
Here is my code from my ASPX page:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>Yahoo! News Top Stories</title>
<meta name="GENERATOR" content="Microsoft Visual
Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET
7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<script language="VB" runat="server">
Private Const YAHOO_RSS_FEED As String
= "http://rss.news.yahoo.com/rss/topstories"
Sub Page_Load(sender as Object, e as EventArgs)
'Cache the top stories for 20 minutes
If Cache("YahooTopStories") Is Nothing then
'Item not in cache, get it manually
Dim dt as DataTable = GetRSSFeed(YAHOO_RSS_FEED)
Cache.Insert("YahooTopStories", dt, Nothing,
DateTime.Now.AddMinutes(20), TimeSpan.Zero)
End If
topStories.DataSource = Cache("YahooTopStories")
topStories.DataBind()
End Sub
Function GetRSSFeed(strURL as String) as DataTable
'Get the XML data
Dim reader as XmlTextReader = New XmlTextReader
(strURL)
'return a new DataSet
Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)
Return ds.Tables(2)
End Function
</script>
<asp:DataGrid runat="server" id="topStories"
AutoGenerateColumns="False"
Font-Name="Arial" Font-Size="10pt"
HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-BackColor="Navy" HeaderStyle-
ForeColor="White"
HeaderStyle-Font-Size="15pt"
AlternatingItemStyle-BackColor="#eeeeee">
<Columns>
<asp:TemplateColumn HeaderText="Yahoo News Top
Stories for <%=Today()%>">
<ItemTemplate>
<a href="<%# DataBinder.Eval
(Container.DataItem, "link")%>">
<%# DataBinder.Eval
(Container.DataItem, "title") %>
</a> <!--(<i><%# DataBinder.Eval
(Container.DataItem, "datePosted") %></i>)-->
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</body>
</HTML>
Do you know what I need to change?
Thanks in advance.