我正在异常
'',十六进制值0x0B,是无效字符。第23行,第22位。
我已经尝试过来自Here的解决方案,但它对我不起作用。由于我的项目是 3.5 版本,我无法使用XmlConvert.IsXmlChar
方法MSDN
如何处理?
答案 0 :(得分:3)
您可以使用以下方法替换这些无效字符。
public static string CleanInvalidXmlChars(this string StrInput)
{
//Returns same value if the value is empty.
if (string.IsNullOrWhiteSpace(StrInput))
{
return StrInput;
}
// From xml spec valid chars:
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
// any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
string RegularExp = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
return Regex.Replace(StrInput, RegularExp, String.Empty);
}