I am using this project : https://github.com/Microsoft/Windows-appsample-rssreader
I want to get thumnails from a RSS feed. Now, the problem is I get errors. I will explain them. First have a look on so far what I did. : I have this class :
public class ArticleViewModel : BindableBase
{
public string thumbnail { get; set; }
public string Title { get; set; }
public string Summary { get; set; }
public string Author { get; set; }
public Uri Link { get; set; }
public DateTimeOffset PublishedDate { get; set; }
public string PublishedDateFormatted => PublishedDate.ToString("MMM dd, yyyy h:mm tt").ToUpper();
public override bool Equals(object obj) =>
obj is ArticleViewModel ? (obj as ArticleViewModel).GetHashCode() == GetHashCode() : false;
public override int GetHashCode() => Link.GetHashCode();
private bool? _isStarred = false;
public bool? IsStarred { get { return _isStarred; } set { SetProperty(ref _isStarred, value); } }
}
For example we take the RSS feed of http://coffeeetech.xyz/feed .
Now here :
var feed = await new SyndicationClient().RetrieveFeedAsync(feedViewModel.Link);
feedViewModel.Name = String.IsNullOrEmpty(feedViewModel.Name) ? feed.Title.Text : feedViewModel.Name;
feedViewModel.Description = feed.Subtitle?.Text ?? String.Empty;
feed.Items.Select(item => new ArticleViewModel
{
thumbnail = item.thumbnail,
// description = WebUtility.HtmlDecode(description);
Title = item.Title.Text,
Summary = item.Summary == null ? string.Empty :
item.Summary.Text.RegexRemove("\\&.{0,4}\\;").RegexRemove("<.*?>"),
Author = item.Authors.Select(a => a.NodeValue).FirstOrDefault(),
Link = item.ItemUri ?? item.Links.Select(l => l.Uri).FirstOrDefault(),
PublishedDate = item.PublishedDate
})
.ToList().ForEach(article =>
{
var favorites = AppShell.Current.ViewModel.FavoritesFeed;
var existingCopy = favorites.Articles.FirstOrDefault(a => a.Equals(article));
article = existingCopy ?? article;
if (!feedViewModel.Articles.Contains(article)) feedViewModel.Articles.Add(article);
});
return true;
Now, the problem is that, in the line thubmnail = item.thumbnail, I get the error that 'thumbnail doesn't exist in current context'
So the question is how to get the thumbnail via SyndicationFeed. I mean, the item thumbnail doesn't exist there. Thanks.
SyndicationItem class represents an item in the feed. This class encapsulates information in the /rss/channel/item element in RSS 2.0 or the atom:entry element in Atom 1.0 .
For the <item>
element in RSS 2.0, there is no sub-element related to thumbnail. So SyndicationItem
do not has a "thumbnail" property. And even we add a "thumbnail" property in this class, it also won't help. For the mapping between SyndicationItem
properties and RSS elements, please see the table under the Remarks section of SyndicationItem class .
Since you want to get the main thumbnail images. I suppose you want to get the <image>
sub-element of <channel>
. If so, you can try with SyndicationFeed.ImageUri
property. This property represents image/uri element in RSS 2.0 . You can add a "thumbnail" property in FeedViewModel
and then set it in RefreshAsync
method like following.
var feed = await new SyndicationClient().RetrieveFeedAsync(feedViewModel.Link);
feedViewModel.Name = String.IsNullOrEmpty(feedViewModel.Name) ? feed.Title.Text : feedViewModel.Name;
feedViewModel.Description = feed.Subtitle?.Text ?? String.Empty;
feedViewModel.thumbnail = feed.ImageUri;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.