0

I'm attempting to parse an RSS feed using C# and the SyndicationFeed class. I'm iterating over the items to get a list of SyndicationItems and that is exposing most of the feed properties, but what I cannot get out is the media:thumbnail element:

    <?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
    xmlns:media="http://search.yahoo.com/mrss/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:ddn="http://discoverydn.com/about">
  <channel>
    <title>Revision3 Feed</title>
    <link>http://revision3.com/user/1564421</link>
    <description>Customized RSS Feed of all your favorite Revision3 shows.</description>
    <language>en-us</language>
    <itunes:explicit>no</itunes:explicit>
    <itunes:summary></itunes:summary>
    <itunes:subtitle></itunes:subtitle>
    <itunes:author>Revision3</itunes:author>
    <itunes:owner>
      <itunes:email>feedback@revision3.com</itunes:email>
      <itunes:name>Revision3</itunes:name>
    </itunes:owner>
    <itunes:image href="http://revision3.com/forum/image.php?u=415677" />
    <itunes:keywords />
    <image>
      <title>Revision3 Feed</title>
      <width>100</width>
      <height>100</height>
      <link>http://revision3.com/user/1564221</link>
      <url>http://revision3.com/forum/image.php?u=415677</url>
    </image>
    <atom:link rel="self" type="application/rss+xml" title="Revision3 Feed" href="http://revision3.com/feed/user/0a7ehtg09b0ab0/" />
    <item>
      <title>Tekzilla Bites - Toyota Announces New Zero-Emission Fuel Cell Vehicle For 2015!</title>
      <link>http://revision3.com/tekzillabites/toyota-fuel-cell</link>
      <description>
&lt;p&gt;This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota&apos;s announced specs, right from the CES show floor.
&lt;/p&gt;
      </description>
      <content:encoded>
&lt;p&gt;This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota&apos;s announced specs, right from the CES show floor.
&lt;/p&gt;
      </content:encoded>
      <author>feedback@revision3.com (Revision3)</author>
      <pubDate>Tue, 07 Jan 2014 07:00:00 GMT</pubDate>
      <itunes:image href="http://revision3.com/forum/image.php?u=415677" />
      <itunes:duration>154</itunes:duration>
      <itunes:explicit>no</itunes:explicit>
      <itunes:keywords>toyota, fuel cell vehicle, hydrogen electric, hydrogen electricity, fcv, fuel cell, water exhaust, electric car, ces 2014</itunes:keywords>
      <itunes:author>Revision3</itunes:author>
      <itunes:subtitle>
This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota's announced specs, 
      </itunes:subtitle>
      <guid isPermaLink="false">/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--hd720p30.h264.mp4</guid>
      <enclosure url="http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--hd720p30.h264.mp4" length="27874999" type="video/mp4" />
      <media:content duration="154" medium="video" fileSize="27874999" url="http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--hd720p30.h264.mp4" type="video/mp4">
        <media:title>Tekzilla Bites - Toyota Announces New Zero-Emission Fuel Cell Vehicle For 2015!</media:title>
        <media:description>
&lt;p&gt;This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota&apos;s announced specs, right from the CES show floor.
&lt;/p&gt;
        </media:description>
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--marge.thumb.jpg" width="640" height="360" />
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--medium.thumb.jpg" width="300" height="169" />
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--mini.thumb.jpg" width="100" height="100" />
        <media:player url="http://revision3.com/tekzillabites/toyota-fuel-cell" />
        <media:rating>nonadult</media:rating>
        <media:keywords>toyota, fuel cell vehicle, hydrogen electric, hydrogen electricity, fcv, fuel cell, water exhaust, electric car, ces 2014</media:keywords>
      </media:content>
      <ddn:id>28583</ddn:id>
    </item>
    <item>
      <title>Film Riot - Mondays: Getting Recognized, Poster Credits &amp; Royalty Free Music!</title>
      <link>http://revision3.com/filmriot/poster-credits</link>
      <description>
Ryan opens up the mail sack and answers some questions!
      </description>
      <content:encoded>
Ryan opens up the mail sack and answers some questions!
      </content:encoded>
      <author>feedback@revision3.com (Revision3)</author>
      <pubDate>Tue, 07 Jan 2014 05:00:00 GMT</pubDate>
      <itunes:image href="http://revision3.com/forum/image.php?u=415677" />
      <itunes:duration>522</itunes:duration>
      <itunes:explicit>no</itunes:explicit>
      <itunes:keywords>getting recognized, getting yourself out there, poster credits, royalty free music, music, getting permission to use music, film riot, mail sack, questions, answers, q&amp;a, ryan connolly</itunes:keywords>
      <itunes:author>Revision3</itunes:author>
      <itunes:subtitle>
Ryan opens up the mail sack and answers some questions!
      </itunes:subtitle>
      <guid isPermaLink="false">/filmriot/0364/filmriot--0364--poster-credits--hd720p30.h264.mp4</guid>
      <enclosure url="http://videos.revision3.com/revision3/web/filmriot/0364/filmriot--0364--poster-credits--hd720p30.h264.mp4" length="73676325" type="video/mp4" />
      <media:content duration="522" medium="video" fileSize="73676325" url="http://videos.revision3.com/revision3/web/filmriot/0364/filmriot--0364--poster-credits--hd720p30.h264.mp4" type="video/mp4">
        <media:title>Film Riot - Mondays: Getting Recognized, Poster Credits &amp; Royalty Free Music!</media:title>
        <media:description>
Ryan opens up the mail sack and answers some questions!
        </media:description>
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/filmriot/0364/filmriot--0364--poster-credits--marge.thumb.jpg" width="640" height="360" />
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/filmriot/0364/filmriot--0364--poster-credits--medium.thumb.jpg" width="300" height="169" />
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/filmriot/0364/filmriot--0364--poster-credits--mini.thumb.jpg" width="100" height="100" />
        <media:player url="http://revision3.com/filmriot/poster-credits" />
        <media:rating>nonadult</media:rating>
        <media:keywords>getting recognized, getting yourself out there, poster credits, royalty free music, music, getting permission to use music, film riot, mail sack, questions, answers, q&amp;a, ryan connolly</media:keywords>
      </media:content>
      <ddn:id>28579</ddn:id>
    </item>
    <item>
      <title>Tekzilla Bites - Roku&apos;s Smart TV, More Channels, No Box- CES 2014</title>
      <link>http://revision3.com/tekzillabites/roku-tv-ces-2014</link>
      <description>
&lt;p&gt;Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton has the details. &lt;/p&gt;
      </description>
      <content:encoded>
&lt;p&gt;Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton has the details. &lt;/p&gt;
      </content:encoded>
      <author>feedback@revision3.com (Revision3)</author>
      <pubDate>Tue, 07 Jan 2014 05:00:00 GMT</pubDate>
      <itunes:image href="http://revision3.com/forum/image.php?u=415677" />
      <itunes:duration>105</itunes:duration>
      <itunes:explicit>no</itunes:explicit>
      <itunes:keywords>roku tv, roku, tcl, hisense, ces2014, ces 2014, roku lt, ruku 1, streaming, stream, media, tekzilla, roku remote, set top box, coard cutting</itunes:keywords>
      <itunes:author>Revision3</itunes:author>
      <itunes:subtitle>
Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton 
      </itunes:subtitle>
      <guid isPermaLink="false">/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--hd720p30.h264.mp4</guid>
      <enclosure url="http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--hd720p30.h264.mp4" length="21262105" type="video/mp4" />
      <media:content duration="105" medium="video" fileSize="21262105" url="http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--hd720p30.h264.mp4" type="video/mp4">
        <media:title>Tekzilla Bites - Roku&apos;s Smart TV, More Channels, No Box- CES 2014</media:title>
        <media:description>
&lt;p&gt;Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton has the details. &lt;/p&gt;
        </media:description>
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--marge.thumb.jpg" width="640" height="360" />
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--medium.thumb.jpg" width="300" height="169" />
        <media:thumbnail url="http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--mini.thumb.jpg" width="100" height="100" />
        <media:player url="http://revision3.com/tekzillabites/roku-tv-ces-2014" />
        <media:rating>nonadult</media:rating>
        <media:keywords>roku tv, roku, tcl, hisense, ces2014, ces 2014, roku lt, ruku 1, streaming, stream, media, tekzilla, roku remote, set top box, coard cutting</media:keywords>
      </media:content>
      <ddn:id>28582</ddn:id>
    </item>
  </channel>
</rss>

The entire media:content block is not deserialized from the XML passed in. I've iterated over the entire element extensions block using

foreach (SyndicationElementExtension extension in item.ElementExtensions)

but its not in there. Is there any way I can tell the SyndicationFeed.Load() method to also parse this block for me:

SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
tshepang
  • 12,111
  • 21
  • 91
  • 136
LDJ
  • 6,896
  • 9
  • 52
  • 87
  • When I parse the XML you've provided using SyndicationFeed.Load(XmlReader.Create(new StringReader(data))), I get the error "The element with name 'item' and namespace '' is not an allowed feed format". Are you doing anything extra that you haven't posted, or could you show how you've created the xml reader to get past this? – atom.gregg Jan 07 '14 at 11:17
  • Sorry, that was just a sample of one of the items. I've added a complete xml sample now that should parse – LDJ Jan 07 '14 at 11:23
  • Alright, confirmed. The media elements do not get written.. There may be a way to load them, maybe during the XmlReader construction if that is what is responsible for them being missing, but is it okay to create a solution using plain XDocument and Linq-to-Xml? – atom.gregg Jan 07 '14 at 11:30

4 Answers4

2

You can check our MediaRssSharp for parsing media rss feeds. MediaRssSharp does most of the mrss format parsing for you including optional/non-optional elements.

Kobynet
  • 983
  • 11
  • 23
1

Ok.. Found your data.

Try this, where the data variable is the string you've provided.

The inner XElement.Value contains the entire media block, so you will then need to query it and select which-ever element you want.

The Dump() method is an extension method available from LinqPad which is where I do my debugging.

var data = @"<?xml version=""1.0"" encoding=""utf-8""?>
<rss version=""2.0"" xmlns:itunes=""http://www.itunes.com/dtds/podcast-1.0.dtd""
    xmlns:content=""http://purl.org/rss/1.0/modules/content/""
    xmlns:creativeCommons=""http://backend.userland.com/creativeCommonsRssModule""
    xmlns:media=""http://search.yahoo.com/mrss/""
    xmlns:atom=""http://www.w3.org/2005/Atom""
    xmlns:ddn=""http://discoverydn.com/about"">
  <channel>
    <title>Revision3 Feed</title>
    <link>http://revision3.com/user/1564421</link>
    <description>Customized RSS Feed of all your favorite Revision3 shows.</description>
    <language>en-us</language>
    <itunes:explicit>no</itunes:explicit>
    <itunes:summary></itunes:summary>
    <itunes:subtitle></itunes:subtitle>
    <itunes:author>Revision3</itunes:author>
    <itunes:owner>
      <itunes:email>feedback@revision3.com</itunes:email>
      <itunes:name>Revision3</itunes:name>
    </itunes:owner>
    <itunes:image href=""http://revision3.com/forum/image.php?u=415677"" />
    <itunes:keywords />
    <image>
      <title>Revision3 Feed</title>
      <width>100</width>
      <height>100</height>
      <link>http://revision3.com/user/1564221</link>
      <url>http://revision3.com/forum/image.php?u=415677</url>
    </image>
    <atom:link rel=""self"" type=""application/rss+xml"" title=""Revision3 Feed"" href=""http://revision3.com/feed/user/0a7ehtg09b0ab0/"" />
    <item>
      <title>Tekzilla Bites - Toyota Announces New Zero-Emission Fuel Cell Vehicle For 2015!</title>
      <link>http://revision3.com/tekzillabites/toyota-fuel-cell</link>
      <description>
&lt;p&gt;This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota&apos;s announced specs, right from the CES show floor.
&lt;/p&gt;
      </description>
      <content:encoded>
&lt;p&gt;This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota&apos;s announced specs, right from the CES show floor.
&lt;/p&gt;
      </content:encoded>
      <author>feedback@revision3.com (Revision3)</author>
      <pubDate>Tue, 07 Jan 2014 07:00:00 GMT</pubDate>
      <itunes:image href=""http://revision3.com/forum/image.php?u=415677"" />
      <itunes:duration>154</itunes:duration>
      <itunes:explicit>no</itunes:explicit>
      <itunes:keywords>toyota, fuel cell vehicle, hydrogen electric, hydrogen electricity, fcv, fuel cell, water exhaust, electric car, ces 2014</itunes:keywords>
      <itunes:author>Revision3</itunes:author>
      <itunes:subtitle>
This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota's announced specs, 
      </itunes:subtitle>
      <guid isPermaLink=""false"">/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--hd720p30.h264.mp4</guid>
      <enclosure url=""http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--hd720p30.h264.mp4"" length=""27874999"" type=""video/mp4"" />
      <media:content duration=""154"" medium=""video"" fileSize=""27874999"" url=""http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--hd720p30.h264.mp4"" type=""video/mp4"">
        <media:title>Tekzilla Bites - Toyota Announces New Zero-Emission Fuel Cell Vehicle For 2015!</media:title>
        <media:description>
&lt;p&gt;This year at their 2014 CES press conference, Toyota announced the Fuel Cell Vehicle (FCV): a hydrogen-powered vehicle whose only emission is water vapor going to market in 2015. Join Patrick for a look at the car, plus some of Toyota&apos;s announced specs, right from the CES show floor.
&lt;/p&gt;
        </media:description>
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--marge.thumb.jpg"" width=""640"" height=""360"" />
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--medium.thumb.jpg"" width=""300"" height=""169"" />
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0025/tekzilla--tekzillabites--0025--toyota-fuel-cell--mini.thumb.jpg"" width=""100"" height=""100"" />
        <media:player url=""http://revision3.com/tekzillabites/toyota-fuel-cell"" />
        <media:rating>nonadult</media:rating>
        <media:keywords>toyota, fuel cell vehicle, hydrogen electric, hydrogen electricity, fcv, fuel cell, water exhaust, electric car, ces 2014</media:keywords>
      </media:content>
      <ddn:id>28583</ddn:id>
    </item>
    <item>
      <title>Film Riot - Mondays: Getting Recognized, Poster Credits &amp; Royalty Free Music!</title>
      <link>http://revision3.com/filmriot/poster-credits</link>
      <description>
Ryan opens up the mail sack and answers some questions!
      </description>
      <content:encoded>
Ryan opens up the mail sack and answers some questions!
      </content:encoded>
      <author>feedback@revision3.com (Revision3)</author>
      <pubDate>Tue, 07 Jan 2014 05:00:00 GMT</pubDate>
      <itunes:image href=""http://revision3.com/forum/image.php?u=415677"" />
      <itunes:duration>522</itunes:duration>
      <itunes:explicit>no</itunes:explicit>
      <itunes:keywords>getting recognized, getting yourself out there, poster credits, royalty free music, music, getting permission to use music, film riot, mail sack, questions, answers, q&amp;a, ryan connolly</itunes:keywords>
      <itunes:author>Revision3</itunes:author>
      <itunes:subtitle>
Ryan opens up the mail sack and answers some questions!
      </itunes:subtitle>
      <guid isPermaLink=""false"">/filmriot/0364/filmriot--0364--poster-credits--hd720p30.h264.mp4</guid>
      <enclosure url=""http://videos.revision3.com/revision3/web/filmriot/0364/filmriot--0364--poster-credits--hd720p30.h264.mp4"" length=""73676325"" type=""video/mp4"" />
      <media:content duration=""522"" medium=""video"" fileSize=""73676325"" url=""http://videos.revision3.com/revision3/web/filmriot/0364/filmriot--0364--poster-credits--hd720p30.h264.mp4"" type=""video/mp4"">
        <media:title>Film Riot - Mondays: Getting Recognized, Poster Credits &amp; Royalty Free Music!</media:title>
        <media:description>
Ryan opens up the mail sack and answers some questions!
        </media:description>
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/filmriot/0364/filmriot--0364--poster-credits--marge.thumb.jpg"" width=""640"" height=""360"" />
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/filmriot/0364/filmriot--0364--poster-credits--medium.thumb.jpg"" width=""300"" height=""169"" />
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/filmriot/0364/filmriot--0364--poster-credits--mini.thumb.jpg"" width=""100"" height=""100"" />
        <media:player url=""http://revision3.com/filmriot/poster-credits"" />
        <media:rating>nonadult</media:rating>
        <media:keywords>getting recognized, getting yourself out there, poster credits, royalty free music, music, getting permission to use music, film riot, mail sack, questions, answers, q&amp;a, ryan connolly</media:keywords>
      </media:content>
      <ddn:id>28579</ddn:id>
    </item>
    <item>
      <title>Tekzilla Bites - Roku&apos;s Smart TV, More Channels, No Box- CES 2014</title>
      <link>http://revision3.com/tekzillabites/roku-tv-ces-2014</link>
      <description>
&lt;p&gt;Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton has the details. &lt;/p&gt;
      </description>
      <content:encoded>
&lt;p&gt;Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton has the details. &lt;/p&gt;
      </content:encoded>
      <author>feedback@revision3.com (Revision3)</author>
      <pubDate>Tue, 07 Jan 2014 05:00:00 GMT</pubDate>
      <itunes:image href=""http://revision3.com/forum/image.php?u=415677"" />
      <itunes:duration>105</itunes:duration>
      <itunes:explicit>no</itunes:explicit>
      <itunes:keywords>roku tv, roku, tcl, hisense, ces2014, ces 2014, roku lt, ruku 1, streaming, stream, media, tekzilla, roku remote, set top box, coard cutting</itunes:keywords>
      <itunes:author>Revision3</itunes:author>
      <itunes:subtitle>
Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton 
      </itunes:subtitle>
      <guid isPermaLink=""false"">/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--hd720p30.h264.mp4</guid>
      <enclosure url=""http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--hd720p30.h264.mp4"" length=""21262105"" type=""video/mp4"" />
      <media:content duration=""105"" medium=""video"" fileSize=""21262105"" url=""http://videos.revision3.com/revision3/web/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--hd720p30.h264.mp4"" type=""video/mp4"">
        <media:title>Tekzilla Bites - Roku&apos;s Smart TV, More Channels, No Box- CES 2014</media:title>
        <media:description>
&lt;p&gt;Roku known for their ever popular line up of stand-alone media streaming devices, shook things up at CES 2014 this year. Enter: Roku TV, a TV with the Roku platform baked in and a few new extras that will surprise even veteran Roku users. Patrick Norton has the details. &lt;/p&gt;
        </media:description>
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--marge.thumb.jpg"" width=""640"" height=""360"" />
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--medium.thumb.jpg"" width=""300"" height=""169"" />
        <media:thumbnail url=""http://videos.revision3.com/revision3/images/shows/tekzilla/tekzillabites/0024/tekzilla--tekzillabites--0024--roku-tv-ces-2014--mini.thumb.jpg"" width=""100"" height=""100"" />
        <media:player url=""http://revision3.com/tekzillabites/roku-tv-ces-2014"" />
        <media:rating>nonadult</media:rating>
        <media:keywords>roku tv, roku, tcl, hisense, ces2014, ces 2014, roku lt, ruku 1, streaming, stream, media, tekzilla, roku remote, set top box, coard cutting</media:keywords>
      </media:content>
      <ddn:id>28582</ddn:id>
    </item>
  </channel>
</rss>";

var rss = new Rss20FeedFormatter();
rss.ReadFrom(XmlReader.Create(new StringReader(data)));

var elements = rss.Feed.Items.SelectMany(s => s.ElementExtensions.Select(x => x.GetObject<XElement>().Value));
elements.Dump();

Another SO answer which might answer your question can be found here: Reading non-standard elements in a SyndicationItem with SyndicationFeed.

Cheers, Aaron

Community
  • 1
  • 1
atom.gregg
  • 987
  • 8
  • 14
  • Hi, When I step through the code above, the elements variable doesn't contain anything. selctor = null and source = null. Thanks – LDJ Jan 07 '14 at 14:27
  • The code I've posted works when using the XML you provided. There's nothing special going on in there, I've only moved the ElementExtensions to the inner block, ie. for each Item in the feed. Can you try running up LinqPad and running the script I've posted, I'll update it so it includes the sample XML so you just need to copy/paste. Then we can look further into what it is you want out of the RSS feed. Some of the solutions in the link provide alternatives which might be relevent to your case, we can also discuss this. – atom.gregg Jan 07 '14 at 18:00
  • Thanks - got it working now. Have to manually parse the Elements which seems a little slower but at least I can get to any field in the feed now, which SyndicationFeed didn't allow me to do. :) – LDJ Jan 08 '14 at 08:23
1

I added an extension method for the SyndicationItem class. Just create a class called 'ExtensionMethods.cs' in the root of your project and use the code below. Be sure to change the namespace to match that of your project.

using System;

namespace RFAnnouncer
{
    public static class ExtensionMethods
    {
        public static string GetEnclosureUri(this System.ServiceModel.Syndication.SyndicationItem item)
        {
            for (int i = 0; i < item.Links.Count; i++)
            {
                if (item.Links[i].RelationshipType == "enclosure")
                {
                    return item.Links[i].Uri.AbsoluteUri;
                }
            }
            return "";
        }
    }
}
Joshua
  • 617
  • 9
  • 23
0

This is my solution. I return the first thumbnail image.

// Read the feed
while (await feedReader.Read())
{
    if (feedReader.ElementType == SyndicationElementType.Item)
    {
        // Read the item as generic content
        ISyndicationContent content = await feedReader.ReadContent();

        // Parse the item if needed (unrecognized tags aren't available)
        // Utilize the existing parser
        ISyndicationItem item = parser.CreateItem(content);

        string urlImage = GetThumbailsImage(content, url);
        rssNewsItems.Add(item.ConvertToNewsItem(urlImage));
    }
}

private string GetThumbailsImage(ISyndicationContent content, string source)
{
    // Get <media:thumbnail> field
    ISyndicationContent customElement = content.Fields.FirstOrDefault(f => f.Name == "thumbnail");
    var thimbUrl = customElement.Attributes.FirstOrDefault(a => a.Name == "url");
    return thimbUrl?.Value;
}
dev-siberia
  • 2,746
  • 2
  • 21
  • 17