C# LoadXml 时发生 hexadecimal value 0x08, is an invalid character 错误

2023-07-31 15:06:17 码农 1033

解决 XmlDocument 在调用 LoadXml 方法时发生 hexadecimal value 0x08, is an invalid character 和 hexadecimal value 0x12, is an invalid character 等错误。

原因是有很多符号不能在XML代码中出现,所以我们要替换掉:

private string ReplaceHexadecimalSymbols(string txt)
{
	if (txt != "")
	{
		string r = "[\x00-\x08\x0B\x0C\x0E-\x1F]";
		return Regex.Replace(txt, r, "", RegexOptions.Compiled);
	}
	else
	{
		return "";
	}
}
—— 完 ——
  • Unity打包时提示错误:The type or namespace name ‘MenuItemAttribute‘ could not be found
  • 关于线性组织结构的说法,错误的是( )。
  • 采用单价合同指标时,对于投标书中明显的数字计算错误,业主有权
  • 关于小导管注浆说法错误的是( )。
  • 【201305-单选42】关于GIS在农业、林业、水利等多个领域的应用,以下说明错误的是:
  • C#中像素与毫米之间换算方法
  • 上网出现的20种错误信息分析
  • Vue.js 中组件名称错误问题解析
  • Docker: wsl update failed: update failed: updating wsl: exit code: 4294967295: running WSL command wsl.exe
  • 根据《招标投标法》,中标通知书自( )发生法律效力。

© CopyRight 2014~2024 薄学网.