我有问题。我编程的Windows Phone 8.0应用程序,我没有看到我的应用程序中的任何图片。大概错误是在正则表达式,因为在调试regImg没有任何比赛我在我的RSS中看不到任何图片
类MainPage.xaml.cs中
string strURL = "https://news.google.com/news? cf=all&ned=pl_pl&hl=pl&topic=b&output=rss"; // URL of RssFeeds.
和类ImageFromRssText.cs
public class ImageFromRssText : IValueConverter
{
// Get images from each SyndicationItem.
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null) return null;
List<ImageItem> listUri = GetHtmlImageUrlList(value.ToString());
return listUri;
}
/// <summary>
/// Get the URL of the all pictures from the HTML.
/// </summary>
/// <param name="sHtmlText">HTML code</param>
/// <returns>URL list of the all pictures</returns>
public static List<ImageItem> GetHtmlImageUrlList(string sHtmlText)
{
// The definition of a regular expression to match img tag.
Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
// The search for a matching string.
MatchCollection matches = regImg.Matches(sHtmlText);
int i = 0;
List<ImageItem> imgUrlList = new List<ImageItem>();
// Get a list of matches
foreach (Match match in matches)
{
imgUrlList.Add(new ImageItem("img" + i, match.Groups["imgUrl"].Value));
i++;
}
return imgUrlList;
}
1.代替'[\ S \ t \ r \ n] *'用'\ S *' - 2.使用'\ /?'而不是'/?';)。 –
3.如何使用简单的正则表达式像'] *?src \ s * = \ s * [“''](? [^”''] *)[“''] [^>] *> '? )。 –
任何解决方案不起作用:( – Remi