发布时间:2018-07-19编辑:佚名阅读(1708)
//过滤方法 public static string FilterXmlErrorCode(string xml) { foreach (char c in xml) { if (!IsLegalXmlChar(c)) { xml = xml.Replace(c.ToString(), ""); } } return xml; } //xml 无效字符检查 private static bool IsLegalXmlChar(int character) { return ( character == 0x9 /* == '/t' == 9 */ || character == 0xA /* == '/n' == 10 */ || character == 0xD /* == '/r' == 13 */ || (character >= 0x20 && character <= 0xD7FF) || (character >= 0xE000 && character <= 0xFFFD) || (character >= 0x10000 && character <= 0x10FFFF) ); } //调用 string example = "xxxxx"; example = FilterXmlErrorCode(example);
关键字: C#去除XML无效字符
0人
0人
0人
0人