Question

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> 
Was it helpful?

Solution

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();

OTHER TIPS

try this

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();

or

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top