2011-03-23 70 views
1

我正在努力解析Google提要。我对正常的RSS没有任何问题,但是这个稍微复杂的基于ATOM的提要对于我来说并不适用于相同的简单解析代码。 我怎样才能进入elelemts?Windows Phone WP7帮助解析XML提要

我使用的以下代码不起作用,它不返回任何集合,但可以很好地与RSS获取<项目>元素,因为它们可能是因为它们没有属性。

XElement _xml = XElement.Parse(response); 
foreach (XElement value in _xml.Elements("entry")) 
{ 
... 
} 

当他们有gd:etag =“...”时,我该如何到达入口元素?

任何帮助表示赞赏。

进料的样品--------------- ----------------------

<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/&quot;DUMFR3YyfCt7ImA9WxNTFU0.&quot;"> 
<id>https://docs.google.com/feeds/default/private/full</id> 
<updated>2009-08-17T11:10:16.894Z</updated> 
<title>Available Documents - [email protected]</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> 

回答

1

您应该使用Linq。将xml加载到XDocument对象中,然后针对具有gd:etag =“”的条目运行一个Linq查询。

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. 
       };