从rss的descrption标签中提取图像提供windowsphone8

时间:2014-06-11 09:54:27

标签: windows-phone-8

我试图从很多天的描述标签中获取图片。下面是描述标签。

<p style="text-align: center;"><img hspace="1" height="312" border="1" align="middle" width="300" vspace="3" src="/recipeuserfiles/Katte Pongali-andhra recipes-healthy recipes.PNG" alt="" /></p> <ul> <li>Mix the rice and Green gram dal Cook in pressure cooker and keep it side. </li> <li>Now take a vessel and heat the ghee and add add pepper, cumin seeds, curry leaves and cashew nuts to it. </li> <li>Then add the cokked rice and dal , salt and mix it properly. </li> <li>Delicious pongali is ready to taste. Have it with any of your favorite chutney.</li> </ul>

我要解析的整个代码是

using System;
using Microsoft.Phone.Controls;
using System.Windows;
using System.Net;
using System.Xml.Serialization;
using System.Xml.Linq;

namespace Recipes
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();


            // is there network connection available
            if(!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                MessageBox.Show("No network connection available!");
                return;
        }
        // start loading RSS-data
        WebClient downloader = new WebClient();
        Uri uri = new Uri("http://teluguone.com/recipes/feeds/recipefeeds/rice-4.rss", UriKind.Absolute);
        downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(channelDownloaded);
        downloader.DownloadStringAsync(uri);
    }
    string src;
    string desc;


    void channelDownloaded(object sender, DownloadStringCompletedEventArgs e)
    {
        try
        {



            if (e.Result == null || e.Error != null)
            {
                MessageBox.Show("There was an error downloading the XML-file!");
            }
            else
            {
                // Deserialize if download succeeds
                XDocument document = XDocument.Parse(e.Result);
                XmlSerializer serializer = new XmlSerializer(typeof(Channel));
                Channel channel = (Channel)serializer.Deserialize(document.CreateReader());
                itemList.ItemsSource = channel.Collection;

             Pattern p = Pattern.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>");
            Matcher m = p.matcher(desc);
              if (m.find()) 
             src = m.group(1);
            src="http://www.teluguone.com"+src;
             return src.replaceAll("\\s", "");
            //Log.d("src", src);
            }
        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.InnerException.Message);
            MessageBox.Show(ex.ToString());
        }
    }
}

我遇到了错误 Error:'string' does not contain a definition for 'replaceAll' and no extension method 'replaceAll' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?

请有人帮助我。我很多天都在努力解决这个问题并发布在不同的博客中。我没有得到答案。

非常感谢任何帮助。 非常感谢

1 个答案:

答案 0 :(得分:0)

使用&#34;内容&#34;要检索HTML并使用正则表达式功能的元素,

var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
var match=reg.Match(source);
if(match.Success)
{
  var encod = match.Groups["imgSrc"].Value;
}

希望有所帮助:)

相关问题