Получить медиа-элементы из RSS с помощью SyndicationFeed
Я пытаюсь проанализировать RSS-канал, используя C# и класс SyndicationFeed. Я перебираю элементы, чтобы получить список SyndicationItems, который раскрывает большинство свойств канала, но что я не могу получить, так это элемент 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>
<p>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, right from the CES show floor.
</p>
</description>
<content:encoded>
<p>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, right from the CES show floor.
</p>
</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>
<p>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, right from the CES show floor.
</p>
</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 & 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&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 & 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&a, ryan connolly</media:keywords>
</media:content>
<ddn:id>28579</ddn:id>
</item>
<item>
<title>Tekzilla Bites - Roku's Smart TV, More Channels, No Box- CES 2014</title>
<link>http://revision3.com/tekzillabites/roku-tv-ces-2014</link>
<description>
<p>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. </p>
</description>
<content:encoded>
<p>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. </p>
</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's Smart TV, More Channels, No Box- CES 2014</media:title>
<media:description>
<p>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. </p>
</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>
Весь блок media:content не десериализован из переданного XML. Я перебрал весь блок расширений элементов, используя
foreach (SyndicationElementExtension extension in item.ElementExtensions)
но его там нет. Можно ли как-то сказать, что метод SyndicationFeed.Load() также проанализировать этот блок для меня:
SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
3 ответа
Хорошо.. Нашел ваши данные.
Попробуйте это, где переменная данных - это строка, которую вы указали.
Внутренний 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>
<p>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, right from the CES show floor.
</p>
</description>
<content:encoded>
<p>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, right from the CES show floor.
</p>
</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>
<p>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, right from the CES show floor.
</p>
</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 & 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&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 & 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&a, ryan connolly</media:keywords>
</media:content>
<ddn:id>28579</ddn:id>
</item>
<item>
<title>Tekzilla Bites - Roku's Smart TV, More Channels, No Box- CES 2014</title>
<link>http://revision3.com/tekzillabites/roku-tv-ces-2014</link>
<description>
<p>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. </p>
</description>
<content:encoded>
<p>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. </p>
</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's Smart TV, More Channels, No Box- CES 2014</media:title>
<media:description>
<p>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. </p>
</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-ответ, который может ответить на ваш вопрос, можно найти здесь: Чтение нестандартных элементов в SyndicationItem с помощью SyndicationFeed.
Ура, Аарон
Я добавил метод расширения для класса 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 "";
}
}
}
Вы можете проверить наш MediaRssSharp для анализа RSS-каналов мультимедиа. MediaRssSharp выполняет для вас большую часть анализа формата mrss, включая необязательные / необязательные элементы.
Это моё решение. Я возвращаю первое уменьшенное изображение.
// 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;
}