[英]Read more than one node in rss xml
how can I read more category in this XML page? 如何在此XML页面中阅读更多类别? http://feeds.feedburner.com/passionea300allora?format=xml
http://feeds.feedburner.com/passionea300allora?format=xml
Because, now I'm using this to read information: 因为,现在我正在用它来读取信息:
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
};
But this report me only first category (in the first news, at the moment, it is "Regolamento" at line 19). 但是,此报告仅报告第一类(目前,第一个新闻是第19行的“ Regolamento”)。 I need to read more category and, if possible, author name too
我需要阅读更多类别,如果可能,还要阅读作者姓名
Instead of rss.Element("category")
, use rss.Elements("category")
. 代替
rss.Element("category")
,使用rss.Elements("category")
。 That will return a IEnumerable<XElement>
. 这将返回
IEnumerable<XElement>
。 You can change your property type to list of categories, or if you want to store values only you can store it into a List<string>
like this: 您可以将属性类型更改为类别列表,或者如果只想存储值,则可以将其存储到
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();
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.