开发者

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) _
}

DataGridVie开发者_如何学JAVAw1.DataSource = rssResultSet


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜