Reputation: 1415
I'm developing a wp7 app, It's a simple rss reader. I'm able to recuperate the date, the title and the description...
But when I try to recuperate an image from this rss feed, I catch a NullReferenceException... Here the wrong line :
itemRss.Image = new Uri(item.Element("enclosure").Attribute("url").Value);
So, what's the good instruction to recuperate the image please ? Thanks in advance
Upvotes: 1
Views: 1007
Reputation: 1101
you need to recuperate the uri from <img src="http://www.artdeseduire.com/wp-content/uploads/2012/02/Comment-choisir-son-jean.jpg" alt="Comment choisir son jean Comment choisir son jean simplement et rapidement..." title="Comment choisir son jean" width="207" height="302" class="alignright size-full wp-image-14072" />
;
var reg1 = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
var match1 = reg1.Match(source);
if (match1.Success)
{
temp.UrlImage = new Uri(match1.Groups["imgSrc"].Value, UriKind.Absolute);
}
Upvotes: 2
Reputation: 3529
There are no "enclosure" element in this feed.
When you say the image, it is the one contained in the text? If so, use the "content" element to retrieve the HTML and use the regex that I have already given in this answer.
var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
var match=reg.Match(source);
if(match.Success)
{
var encod = match.Groups["imgSrc"].Value;
}
Upvotes: 5