我有这样的 TAG xml 文件:
<Question>dzia&#322;owa</Question>
我正在使用 XmlTextReader 读取此文件,对于此 TAG,我得到如下信息:
działowa
如何在我的 xml 中替换 html 实体编号以获得如下内容:“działowa”?
我有这样的 TAG xml 文件:
<Question>dzia&#322;owa</Question>
我正在使用 XmlTextReader 读取此文件,对于此 TAG,我得到如下信息:
działowa
如何在我的 xml 中替换 html 实体编号以获得如下内容:“działowa”?
您的示例中唯一的 HTML 实体是&
. 然后你会得到一些正常的文本,上面写着#322;
. 你要么想要
<Question>dzia&łowa</Question>
这会给“dzia&łowa”(可能不是你想要的)
或者
<Question>działowa</Question>
这将给“działowa”
我想我解决了部分问题(将 &#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;
}