Input is not proper UTF-8, indicate encoding !错误处理

xml 中若是包含部分 ascii 控制字符(小数字)则 chrome会报告以下类型错我:css

This page contains the following errors: error on line 20 at column 89: Input is not proper UTF-8, indicate encoding ! Bytes: 0x08 0xE8 0xBA 0xB2 Below is a rendering of the page up to the first error.

解决办法:replace 这些字符chrome

 public static string ReplaceXMLInvaidChar(string xmlStr)
        {
           return Regex.Replace(xmlStr, "[\x00-\x1F\x7F]","");
           
        }

  

缘由:XML 规范不支持以下字符
#x0 - #x8 (ASCII 0 - 8) #xB - #xC (ASCII 11 - 12) #xE - #x1F (ASCII 14 - 31)

参看文档:https://support.microsoft.com/en-us/kb/315580ruby

原文地址:https://blog.csdn.net/isaisai/article/details/53899089spa

相关文章
相关标签/搜索