在rss xml中读取多个节点

时间:2014-03-21 22:44:18

标签: c# xml windows-phone

如何在此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”)。 我需要阅读更多类别,如果可能的话,还需要阅读作者名称

1 个答案:

答案 0 :(得分:1)

而不是rss.Element("category"),请使用rss.Elements("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();
                      };
相关问题