I'm struggling to parse a Google feed. I have no problems with normal RSS but this slightly more complex ATOM based feed is not working for me with the same simple parsing code. How can I get to the entry elelemts?
The following code I am using does not work, it returns no collection, but works fine with RSS for getting <item> elements presumably becuase they have no attributes.
XElement _xml = XElement.Parse(response);
foreach (XElement value in _xml.Elements("entry"))
{
...
}
How can I get to the entry elements when they have a gd:etag="..."?
Any help appreciated.
--------------- SAMPLE OF THE FEED ----------------------
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:docs="http://schemas.google.com/docs/2007" xmlns:batch="http://schemas.google.com/gdata/batch"
xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/"DUMFR3YyfCt7ImA9WxNTFU0."">
<id>htt开发者_高级运维ps://docs.google.com/feeds/default/private/full</id>
<updated>2009-08-17T11:10:16.894Z</updated>
<title>Available Documents - user@gmail.com</title>
<openSearch:startIndex>1</openSearch:startIndex>
<entry gd:etag="'EVJVTBICRit7ImBq'">
<id>https://docs.google.com/feeds/id/document%3A12345</id>
<published>2009-07-22T19:02:57.616Z</published>
<updated>2009-07-29T20:31:39.804Z</updated>
</entry>
<entry gd:etag="'HhJSFgpeRyt7ImBq'">
<id>https://docs.google.com/feeds/id/pdf%3A12345</id>
<published>2009-04-09T18:23:09.035Z</published>
<updated>2009-04-09T18:23:09.035Z</updated>
</entry>
...
</feed>
You should use Linq. Load the xml into an XDocument object and then run a Linq query against that for the entries that have gd:etag="".
XDocument feedXml = XDocument.Load(uriToFeed);
var feedInfo = from item in publicationsXml.Descendants("feed")
select new Feed // this can be a class that has the properties
// from each feed that you care about
{
// code to retreive info you need from the item
ID = item.Element("id").Value,
//etc.
};
精彩评论