【问题标题】:Windows Phone WP7 Help parsing XML feedWindows Phone WP7 帮助解析 XML 提要
【发布时间】:2011-03-23 23:34:29
【问题描述】:

我正在努力解析 Google 供稿。我对普通的 RSS 没有任何问题,但是这个稍微复杂的基于 ATOM 的提要对我来说不适用于相同的简单解析代码。 我怎样才能到达入口元素?

我使用的以下代码不起作用,它不返回任何集合,但可以与 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 - 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>

【问题讨论】:

    标签: windows-phone-7


    【解决方案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.
                   };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多