Como recuperar a imagem deste feed rss?
-
09-12-2019 - |
Pergunta
Estou desenvolvendo um aplicativo wp7, é um leitor de RSS simples.Consigo recuperar a data, o título e a descrição...
Mas quando tento recuperar uma imagem deste feed RSS, eu pego uma NullReferenceException...Aqui a linha errada:
itemRss.Image = new Uri(item.Element("enclosure").Attribute("url").Value);
Então, qual é a boa instrução para recuperar a imagem, por favor?desde já, obrigado
Solução
Não há elemento "invólucro" neste feed.
Quando você fala a imagem, é aquela contida no texto?Nesse caso, use o elemento "content" para recuperar o HTML e use a regex que já dei nesta resposta.
var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
var match=reg.Match(source);
if(match.Success)
{
var encod = match.Groups["imgSrc"].Value;
}
Outras dicas
você precisa recuperar o uri de <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);
}