SyndicationFeed: How to access content: encoded?

In the Windows 8 Store app, I read some Xml data using SyndicationFeed . Several RSS feed elements contain, for example, content:encoded elements (xmlns: content = '...'). I think there is no way to get the contents of these elements through SyndicationItem ?!

This is why I am trying inside my foreach(SyndicationItem item in feeditems) something like this:

 item.GetXmlDocument(feed.SourceFormat).SelectSingleNode("/item/*:encoded]").InnerText; 

But that does not work. And I have no doubt how to use NamespaceManager , etc. In winrt. At the moment I am accessing the content: encoded using the NextSibling method of another element, but this is not a completely clean way.

So, how can I access the contents of an 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> 
+4
source share
2 answers

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(); 
+2
source

try it

 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(); 
+1
source

Source: https://habr.com/ru/post/1481535/


All Articles