Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SyndicationFeed-项目摘要(RSS描述)-仅从中提取文本_C#_Regex_Rss_Syndicationfeed - Fatal编程技术网

C# SyndicationFeed-项目摘要(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());

我正在使用SyndicationFeed类为文章使用一些rss提要。我想知道如何只从项目的摘要字段中获取文本,而不使用html标记。 例如,有时(并非总是)它包含html标记,例如:div、img、h、p标记:/a>/div>、img src='http'

我想去掉所有的标签。 另外,我不确定它是否能在RSS提要中提供完整的描述

我应该使用正则表达式吗?其他方法

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