2012-03-08 66 views
1

我正在开发一个wp7应用程序,它是一个简单的rss阅读器。我能够休养生息的日期,标题和描述...如何恢复此rss提要的图像?

但是,当我尝试从这个rss feed休养生息的图像,我抓住一个NullReferenceException ......这里错行:

itemRss.Image = new Uri(item.Element("enclosure").Attribute("url").Value); 

那么,有什么好的指示来恢复图像?在此先感谢

回答

5

此提要中没有“封闭”元素。

当你说出图像时,它就是包含在文字中的图像?如果是这样,请使用“content”元素检索HTML并使用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; 
    } 
+0

好的,谢谢,我会检查 – Razor 2012-03-08 17:22:17

2

您需要恢复从<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" /> uri;

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