我正在尝试在C#(Windows Universal App)中阅读字段“dc:creator”而无法正常工作。我需要帮助。请
HttpClient httpClient = new HttpClient();
var rssContent = await httpClient.GetStringAsync("http://www.talkingwindows.com.br/feed");
XElement xmlitems = XElement.Parse(rssContent);
List<XElement> elements = xmlitems.Descendants("item").ToList();
foreach (XElement rss in elements)
{
Lista.Add(
new Model
{
Titulo = rss.Element("title").Value,
DataPublicacao = rss.Element("pubDate").Value,
Descricao = rss.Element("description").Value,
//Autor = rss.Element("dc:creator xmlns:dc=\"http://purl.org/dc/elements/1.1/\"").Value,
Link = rss.Element("link").Value
}
);
}
答案 0 :(得分:2)
要选择特定命名空间中的元素,您需要在其前面添加collector.fail(...)
。在你的情况下,它应该是这样的:
XNamespace
或者如果您愿意,可以这样做:
XNamespace dcNamespace = "http://purl.org/dc/elements/1.1/";
foreach (XElement rss in elements)
{
Lista.Add(
new Model
{
Titulo = rss.Element("title").Value,
DataPublicacao = rss.Element("pubDate").Value,
Descricao = rss.Element("description").Value,
Autor = rss.Element(dcNamespace + "creator").Value,
Link = rss.Element("link").Value
}
);
}
可在此处进一步阅读:
答案 1 :(得分:0)
SyndicationItem.ElementExtensions
是用于解析RSS和Atom订阅源的API。有sample。
在这种情况下,您可以在enter code here
中找到> withCommas
Source: local data frame [326 x 1]
NA
1 16,244,600
2 8,227,103
3 5,959,718
4 3,428,131
5 2,612,878
6 2,471,784
7 2,252,664
8 2,014,775
9 2,014,670
10 1,841,710
.. ...
Classes ‘tbl_df’ and 'data.frame': 326 obs. of 1 variable:
$ : Factor w/ 207 levels ""," 1,008 "," 1,129 ",..: 40 178 143 100 66 63 61 58 57 16 ...
的扩展元素。