I'm trying to parse google calendar events from this url: http://www.google.com/calendar/feeds/amchamlva%40gmail.com/public/full and here is my code:
static IEnumerable<Event> getEntryQuery(XDocument xdoc)
{
return from entry in xdoc.Root.Elements().Where(i => i.Name.LocalName == "entry")
select new Event
{
EventId = entry.Elements().First(i => i.Name.LocalName == "id").Value,
Published = DateTime.Parse(entry.Elements().First(i => i.Name.LocalName == "published").Value),
Title = entry.Elements().First(i => i.Name.LocalName == "title").Value,
Content = entry.Elements().First(i => i.Name.LocalName == "content").Value,
Where = entry.Elements().First(i => i.Name.LocalName == "gd:where").FirstAttribute.Value,
Link = entry.Elements().First(i => i.Name.LocalName == "link").Attribute("href").Value,
};
}
using (StreamReader httpwebStreamReader = new StreamReader(e.Result))
{
var results = httpwebStreamReader.ReadToEnd();
XDocument doc = XDocument.Parse(results);
System.Diagnostics.Debug.WriteLine(doc);
var myFeed = getEntryQuery(doc);
foreach (var feed in myFeed)
{
System.Diagnostics.Debug.WriteLine(feed.Content);
}
}
and It works almost fine, except for this:
Where = entry.Elements().First(i => i.Name.LocalName == "gd:where").FirstAttribute.Value,
I got an exception probably because value it's null, actually i need to get valueString attribue value (for example 'Somewhere' in this case)
<gd:where valueString='Somewhere'/>