vamsivanka
vamsivanka

Reputation: 792

rss feed by linq

I am trying to extract the rss feed using linq. Thought it would be simple, but its is not returning any nodes. probably i have to go the channel/item node, but don't know how.

Dim rssUrl As String = "http://webclip.in/rss.aspx?u=mostliked"
Dim rssDoc As XDocument = XDocument.Load(rssUrl)
Dim rssResultSet = From node In rssDoc.Descendants("item") _
                   Select New With { _
                   .title = node.Element("title").Value, _
                   .link = node.Element("link").Value, _
                   .description = node.Element("description").Value, _
                   .pubDate = Date.Parse(node.Element("pubdate").Value) _
}

DataGridView1.DataSource = rssResultSet

Upvotes: 1

Views: 122

Answers (2)

sidney.andrews
sidney.andrews

Reputation: 5256

Two issues here... First, you should correct this line:

.pubDate = Date.Parse(node.Element("pubDate").Value)

The pubDate is a case-sensitive node in XML. Secondly, your dataSource will never work because LINQ is lazy computation. You have to use ToList() or a similar method that enumerate your collection. If you debug within Visual Studio 2010, you'll see that rssResultSet does not have a value because it is only enumerated when your code calls for it. Replace with this:

DataGridView1.DataSource = rssResultSet.ToList()

My last piece of advice is to set your DataGrid to AutoGenerate it's columns.

Upvotes: 1

Jonathan Bates
Jonathan Bates

Reputation: 1835

the casing on pubdate is wrong. It should be "pubDate". otherwise, works fine.

Upvotes: 0

Related Questions