隨筆 - 100  文章 - 50  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          我收藏的一些文章!

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          About Exception:
          An invalid XML character (Unicode: 0xb) was found in the element content of the document.

          原因:
          從異常來看,很明顯是因為字節(jié)數(shù)組中存在 Unicode: 0xb,而這個字節(jié)在Xml中被認為是非法字符。

          對于一些經(jīng)過編碼或加、解密的字符串中,很容易會出現(xiàn)這個 0xb,
          特別是在加、解密中,經(jīng)常會涉及到字符填充,而填充物通常是 0xb,
          需對于0x00-0x20 都會引起一定的問題,又因為這些字符不可見,因此用通常的編輯器進行編輯的時候找不到問題所在。
          而在轉成String后也覺察不到任何異常。
          所以在轉成XML格式時要對字符串進行檢測:
          *  Verify that no character has a hex value greater than 0xFFFD, or less than 0x20.
          * Check that the character is not equal to the tab ("t), the newline ("n), the carriage return ("r), or is an invalid XML character below the range of 0x20. If any of these characters occur, an exception is thrown.

          pubic String  CheckUnicodeString(String value)
              {
               char xmlChar = value.toCharArray();
              for (int i=0; i < xmlChar.Length; ++i) {
                  if (xmlChar[i] > 0xFFFD)
                  {
                      throw new Exception("Invalid Unicode");
                     //或者直接替換掉0xb 
                      xmlChar[i] =' ';// 用空格替換
                  }
                  else if (xmlChar[i] < 0x20 && xmlChar[i] != 't' & xmlChar[i] != 'n' & xmlChar[i] != 'r')
                  {
                      throw new Exception("Invalid Xml Characters");
                     //或者直接替換掉0xb
                      xmlChar[i] =' ' ;// 用空格替換
                  }
                 return new String( xmlChar );
              }

          posted on 2010-08-06 18:23 fly 閱讀(3844) 評論(0)  編輯  收藏 所屬分類: java學習
          主站蜘蛛池模板: 金湖县| 申扎县| 三台县| 武功县| 宝鸡市| 阜阳市| 昆明市| 绩溪县| 泸定县| 张掖市| 汤阴县| 正安县| 治多县| 银川市| 离岛区| 呼玛县| 普兰店市| 巴林右旗| 唐海县| 浪卡子县| 雅江县| 宝应县| 昔阳县| 壤塘县| 日照市| 牡丹江市| 明光市| 孟村| 永仁县| 伽师县| 黔西县| 沙湾县| 集贤县| 石首市| 淳安县| 界首市| 南靖县| 英山县| 出国| 吐鲁番市| 泗阳县|