Thursday, 15 August 2013

c# - parse xml google calendar event -



c# - parse xml google calendar event -

i'm trying parse google calendar events url: http://www.google.com/calendar/feeds/amchamlva%40gmail.com/public/full , here code:

static ienumerable<event> getentryquery(xdocument xdoc) { homecoming 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, = 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 works fine, except this:

where = entry.elements().first(i => i.name.localname == "gd:where").firstattribute.value,

i got exception because value it's null, need valuestring attribue value (for illustration 'somewhere' in case)

<gd:where valuestring='somewhere'/>

'gd' looks namespace, take @ how work xml namespaces in linq xml:

http://msdn.microsoft.com/en-us/library/bb387093.aspx

http://msdn.microsoft.com/en-us/library/bb669152.aspx

maybe seek along lines of

xnamespace gdns = "some namespace here"; entry.elements(gdns + "where")

c# xml windows-phone google-calendar

No comments:

Post a Comment