I am trying read rss feed of stack overflow using Linq to xml. I am unable to get the entry nodes, as it is returning empty list. This I've tried so far, can any one point out what i am doing wrong here?
Here I am binding to the grid view:
private void StackoverflowFeedList()
{
grdFeedView.DataSource = StackoverflowUtils.GetStackOverflowFeeds();
grdFeedView.DataBind();
}
This is the method which will get all feeds:
public static IEnumerable<StackOverflowFeedItems> GetStackOverflowFeeds ()
{
XNamespace Snmp = "http://www.w3.org/2005/Atom";
XDocument RssFeed = XDocument.Load(@"http://stackoverflow.com/feeds");
var posts = from item in RssFeed.Descendants("entry")
select new StackOverflowFeedItems
{
QuestionID = item.Element(Snmp +"id").Value,
QuestionTitle = item.Element(Snmp +"title").Value,
AuthorName = item.Element(Snmp +"name").Value,
CategoryTag = (from category in item.Elements(Snmp +"category")
orderby category
select category.Value).ToList(),
CreatedDate = DateTime.Parse(item.Element(Snmp +"published").Value),
QuestionSummary = item.Element(Snmp +"summary").Value
};
return posts.ToList();
}
And this is the class I am using for binding:
public class StackOverflowFeedItems
{
public string QuestionID { get; set; }
public string QuestionTitle { get; set; }
public IEnumerable<string> CategoryTag { get; set; }
public string AuthorName { get; set; }
public DateTime CreatedDate { get; set; }
public string QuestionSummary { get; set; }
}