Input is not proper UTF-8, indicate encoding !錯誤處理


xml 中如果包含部分 ascii 控制字符(小數字)則 chrome會報告如下類型錯我:

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 這些字符

 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/315580

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM