1

我有内容:来自 rss 的如下编码文本:

<content:encoded><![CDATA[<P><B>Wednesday, September 26, 2012</B></P>It is Apple.<P>Shops are closed.<br />Parking is not allowed here. Go left and park.<br />All theatres are opened.<br /></P><P><B>Thursday, September 27, 2012</B></P><P>Shops are open.<br />Parking is not allowed here. Go left and park.<br  />All theatres are opened.<br /></P>]]></content:encoded>

使用以下方法,我可以从 HTML 中提取文本:

public static string StripHTML(this string htmlText)
    {
        var reg = new Regex("<[^>]+>", RegexOptions.IgnoreCase);
        return HttpUtility.HtmlDecode(reg.Replace(htmlText, string.Empty));
    }

但是我希望将其中的文本<b></b>插入到 dateArray[] 中,并将其中的文本<p></p>插入到 descriptionArray[] 中,以便我可以显示如下: 在此处输入图像描述

提前致谢。

4

1 回答 1

0
//http://htmlagilitypack.codeplex.com/
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);

var result = doc.DocumentNode.Descendants()
                .Where(n => n is HtmlAgilityPack.HtmlTextNode)
                .Select(n=>new {
                    IsDate = n.ParentNode.Name=="b" ? true: false,
                    Text = n.InnerText,
                })
                .ToList();
于 2012-10-02T20:45:58.250 回答