C# SyndicationFeed-项目摘要(RSS描述)-仅从中提取文本
我正在使用SyndicationFeed类为文章使用一些rss提要。我想知道如何只从项目的摘要字段中获取文本,而不使用html标记。 例如,有时(并非总是)它包含html标记,例如:div、img、h、p标记:/a>/div>、img src='http' 我想去掉所有的标签。 另外,我不确定它是否能在RSS提要中提供完整的描述 我应该使用正则表达式吗?其他方法C# SyndicationFeed-项目摘要(RSS描述)-仅从中提取文本,c#,regex,rss,syndicationfeed,C#,Regex,Rss,Syndicationfeed,我正在使用SyndicationFeed类为文章使用一些rss提要。我想知道如何只从项目的摘要字段中获取文本,而不使用html标记。 例如,有时(并非总是)它包含html标记,例如:div、img、h、p标记:/a>/div>、img src='http' 我想去掉所有的标签。 另外,我不确定它是否能在RSS提要中提供完整的描述 我应该使用正则表达式吗?其他方法 XmlReader reader = XmlReader.Create(response.GetResponseStream());
XmlReader reader = XmlReader.Create(response.GetResponseStream());
SyndicationFeed feed = SyndicationFeed.Load(reader);
foreach (SyndicationItem item in feed.Items)
{
string description= item.Summary; //This contains tags and not only the article text
}
是的,我想正则表达式是实现这一点最简单的内置方法
// Get rid of the tags
description = Regex.Replace(description, @"<.+?>", String.Empty);
// Then decode the HTML entities
description = WebUtility.HtmlDecode(description);
//去掉标记
description=Regex.Replace(description,@“”,String.Empty);
//然后解码HTML实体
description=WebUtility.HtmlDecode(description);