1

我有这样的 TAG xml 文件:

<Question>dzia&amp;#322;owa</Question>

我正在使用 XmlTextReader 读取此文件,对于此 TAG,我得到如下信息:

dzia&#322;owa

如何在我的 xml 中替换 html 实体编号以获得如下内容:“działowa”?

4

2 回答 2

1

您的示例中唯一的 HTML 实体是&amp;. 然后你会得到一些正常的文本,上面写着#322;. 你要么想要

<Question>dzia&amp;&#322;owa</Question>

这会给“dzia&łowa”(可能不是你想要的)

或者

<Question>dzia&#322;owa</Question>

这将给“działowa”

于 2010-10-19T11:28:25.653 回答
0

我想我解决了部分问题(将 &#number; 编码为 char):

public static string EntityNumbersToEntityValues(string s)
        {
            Match match = Regex.Match(s, @"&#(\d+);", RegexOptions.IgnoreCase);
            while(match.Success)
            {
                string v = match.Groups[1].Value;
                string c = char.ConvertFromUtf32(int.Parse(v));
                s = Regex.Replace(s, string.Format("&#{0};", v), c);
                match = match.NextMatch();
            }           
            return s;
        }
于 2010-10-19T13:23:04.930 回答