[英]SyndicationFeed: How to access content:encoded?
在Windows 8商店應用程序中,我正在使用SyndicationFeed
讀取一些Xml數據。 RSS提要的一些項目包含例如content:encoded
(xmlns:content ='...')元素。 我認為沒有辦法通過SyndicationItem獲取這些元素的內容?!
這就是為什么我在我的foreach(SyndicationItem item in feeditems)
這樣的事情:
item.GetXmlDocument(feed.SourceFormat).SelectSingleNode("/item/*:encoded]").InnerText;
但這不起作用。 我要注意如何在winrt中使用NamespaceManager
等。 現在我正在訪問內容:通過其他元素的NextSibling
方法編碼,但這不是一個干凈的方式。
那么如何最好地訪問元素的內容呢?
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="URI">
<channel>
<.../>
<item>
<title>Example entry</title>
<description>Here is some text containing an interesting description.</description>
<link>http://www.wikipedia.org/</link>
<content:encoded>Content I try to access</content:encoded>
</item>
</channel>
</rss>
只需使用XNamespace
XNamespace content = "URI";
var items = XDocument.Parse(xml)
.Descendants("item")
.Select(i => new
{
Title = (string)i.Element("title"),
Description = (string)i.Element("description"),
Link = (string)i.Element("link"),
Encoded = (string)i.Element(content + "encoded"), //<-- ***
})
.ToList();
試試這個
var items = XDocument.Parse(xml)
.Descendants("item")
.Select(i => new
{
Title = (string)i.Element("title"),
Description = (string)i.Element("description"),
Link = (string)i.Element("link"),
Encoded = (string)i.Element("{http://purl.org/dc/elements/1.0/modules/content/}encoded"), //<-- ***
})
.ToList();
要么
var items = XDocument.Parse(xml)
.Descendants("item")
.Select(i => new
{
Title = (string)i.Element("title"),
Description = (string)i.Element("description"),
Link = (string)i.Element("link"),
Encoded = (string)i.Element("{http://purl.org/rss/1.0/modules/content/}encoded"), //<-- ***
})
.ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.