【发布时间】:2013-07-12 05:38:20
【问题描述】:
我有一个很大的 htmlencoded 字符串,我只想解码特定的列入白名单的 html 标签。
有没有办法在 c# 中做到这一点,WebUtility.HtmlDecode() 解码所有内容。
`我正在寻找将通过以下测试的 DecodeSpecificTags() 实现。
[Test]
public void DecodeSpecificTags_SimpleInput_True()
{
string input = "<span>i am <strong color=blue>very</strong> big <br>man.</span>";
string output = "<span>i am <strong color=blue>very</strong> big <br>man.</span>";
List<string> whiteList = new List<string>(){ "strong","br" } ;
Assert.IsTrue(DecodeSpecificTags(whiteList,input) == output);
}`
【问题讨论】:
-
你想达到什么目的?可能还有另一种更好的方法。您还可以做的是获取需要解码的文本的子字符串,然后在解码后附加剩余的编码文本。