如何在xml描述中分隔img标签(RSS FEED) [英] How to separate img tags in description of xml (RSS FEED)

查看:91
本文介绍了如何在xml描述中分隔img标签(RSS FEED)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从RSS提要中检索图像,即在说明中.

I am unable to retrieve images from RSS feeds i.e., in description.

我正在使用以下代码来检索信息.

I am using the following code to retrieve information.

 var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
                 orderby datetime(el.Element("pubDate").Value) descending
             select new
                 {
                     Title = el.Element("title").Value,
                     Link = el.Element("link").Value,
                     Description =el.Element("description").Value,
                     PubDate = datetime(el.Element("pubDate").Value),

                 };

当显示说明"时,文本和图像都将同时显示 我想在描述中将文本和图像分开.能否请让我知道如何进行.

When Description is being displayed, both text and image are being displayed togather I want to separate text and image in description. Can you please let me know how to proceed.

使用的RSS提要: http://news.yahoo.com/rss/

推荐答案

   var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")

                 orderby datetime(el.Element("pubDate").Value) descending

                 select new
                 {
                     Title = el.Element("title").Value,
                     Link = el.Element("link").Value,
                     Description =replace_other(el.Element("description").Value),
                     Image= regex(el.Element("description").Value),
                     PubDate = datetime(el.Element("pubDate").Value),

                 };

   lvFeed.DataSource = rssFeed;
   lvFeed.DataBind(); 

}

 protected string regex(string source)
  {
   var reg1 = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))   
       (?:\"|\')?");
   var match1 = reg1.Match(source);
   if (match1.Success)
   {
       Uri UrlImage = new Uri(match1.Groups["imgSrc"].Value, UriKind.Absolute);
       return UrlImage.ToString();
   }
   else
   {

       return null;
   }

}

这篇关于如何在xml描述中分隔img标签(RSS FEED)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆