I am working on a small widget for BlogEngine.Net. My widget is going to take a person's shared items atom feed and print the title, website url, date, and atom url. To complete this task, I have begun to use Linq and XML.
Here is the problem. The atom feed Google Reader uses is located in the source element, which has an attribute of gr:stream-id. Apparently, the XName does not like having colons in the name. I had to go that route because the Google Reader schema does not exist. If I had that schema, it would solve my issue. How can I get the schema?
Below is a small snippet of my code so far:
protected void Page_Load(object sender, EventArgs e) {
//Replace userid with the unique session id in your Google Reader
//url (the numbers after the F)
getFeed("userid");
}
public class Post {
public String title { get; set; }
public DateTime published { get; set; }
public String postUrl { get; set; }
public String baseUrl { get; set; }
public String atomUrl { get; set; }
}
private void getFeed(String userID) {
String uri = "http://www.google.com/reader/public/atom/user%2F" + userID + "%2Fstate%2Fcom.google%2Fbroadcast";
XNamespace atomNS = "http://www.w3.org/2005/Atom";
//The Google Reader schema link does not exist :(
XNamespace grNS = "http://www.google.com/schemas/reader/atom/";
XDocument feed = XDocument.Load(uri);
var posts = from item in feed.Descendants(atomNS + "entry")
select new Post {
title = item.Element(atomNS + "title").Value,
published = DateTime.Parse(item.Element(atomNS + "published").Value),
postUrl = item.Element(atomNS + "link").Attribute("href").Value,
atomUrl = item.Element(atomNS + "source").Attribute(grNS + "href").Value
};
foreach (Post post in posts) {
output.InnerHtml += "Title: " + post.title + "<br />";
output.InnerHtml += "Published: " + post.published.ToString() + "<br />";
output.InnerHtml += "Post URL: " + post.postUrl + "<br />";
output.InnerHtml += "Atom URL: " + post.atomUrl + "<br />";
output.InnerHtml += "<br />";
}
}
If there is another way to go about this while still using Linq and XML, please let me know. Thanks in advance!