簡體   English   中英

使用SyndicationFeed從RSS獲取媒體元素

[英]Get media elements from RSS using SyndicationFeed

我正在嘗試使用C#和SyndicationFeed類解析RSS提要。 我正在迭代這些項目以獲取SyndicationItems的列表,這是暴露大多數feed屬性,但我無法得到的是media:thumbnail元素:

    <?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>

整個媒體:內容塊不是從傳入的XML反序列化的。我已經使用整個元素擴展塊迭代了

foreach (SyndicationElementExtension extension in item.ElementExtensions)

但它不在那里。 有什么辦法我可以告訴SyndicationFeed.Load()方法也為我解析這個塊:

SyndicationFeed feed = SyndicationFeed.Load(xmlReader);

好的..找到你的數據。

試試這個,數據變量是你提供的字符串。

內部XElement.Value包含整個媒體塊,因此您需要查詢它並選擇所需的元素。

Dump()方法是LinqPad提供的擴展方法,我在這里進行調試。

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

可以在此處找到可能回答您問題的另一個SO答案: 使用SyndicationFeed讀取SyndicationItem中的非標准元素

干杯,亞倫

您可以檢查我們的MediaRssSharp以解析媒體rss提要。 MediaRssSharp為您執行大多數mrss格式解析,包括可選/非可選元素。

我為SyndicationItem類添加了一個擴展方法。 只需在項目的根目錄中創建一個名為“ExtensionMethods.cs”的類,然后使用下面的代碼。 請務必更改命名空間以匹配項目的名稱空間。

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 "";
        }
    }
}

這是我的解決方案。 我返回第一個縮略圖。

// 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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM