【问题标题】:Read more than one node in rss xml在 rss xml 中读取多个节点
【发布时间】:2014-03-21 22:44:17
【问题描述】:

如何在此 XML 页面中阅读更多类别? http://feeds.feedburner.com/passionea300allora?format=xml

因为,现在我用它来阅读信息:

var RSSdata = from rss in XElement.Parse(e.Result).Descendants("item")
                          select new RSSItem
                          {
                              Title1 = rss.Element("title").Value,
                              Description1 = rss.Element("description").Value,
                              Link1 = rss.Element("link").Value,
                              PubDate1 = rss.Element("pubDate").Value,
                              Category1 = rss.Element("category").Value
                          };

但是这个报告我只是第一类(在第一个新闻中,目前,它是第 19 行的“Regolamento”)。 我需要阅读更多类别,如果可能的话,还需要作者姓名

【问题讨论】:

    标签: c# xml windows-phone


    【解决方案1】:

    使用 rss.Elements("category") 代替 rss.Element("category")。这将返回一个IEnumerable<XElement>。您可以将属性类型更改为类别列表,或者如果您只想存储值,可以将其存储到 List<string> 中,如下所示:

    var RSSdata = from rss in XElement.Parse(e.Result).Descendants("item")
                          select new RSSItem
                          {
                              Title1 = (string)rss.Element("title"),
                              Description1 = (string)rss.Element("description"),
                              Link1 = (string)rss.Element("link"),
                              PubDate1 = (string)rss.Element("pubDate"),
                              Categories = rss.Elements("category")
                                               .Select(x => (string)x)
                                               .ToList();
                          };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多