In a Windows 8 Store App I'm reading some Xml data using the SyndicationFeed
. A few items of the RSS feeds contain for example content:encoded
(xmlns:content='...') elements. I think there's no way to get the content of these elements through the SyndicationItem?!
That's why I try inside my foreach(SyndicationItem item in feeditems)
something like this:
item.GetXmlDocument(feed.SourceFormat).SelectSingleNode("/item/*:encoded]").InnerText;
But this doesn't work. And I'm note sure how to use NamespaceManager
etc. in winrt. For now I'm accessing the content:encoded via the NextSibling
method of an other element, but that's not really a clean way.
So how can I access the content of the element best?
<?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>
Just use 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();