XML操作时异常:(十六进制值 0x__) 是无效的字符。

方法一:

设置 CheckCharacters=false。

XmlReaderSettings xmlReaderSettings = new XmlReaderSettings { CheckCharacters = false };

方法二:

如果在第三方类库中,无法设置CheckCharacters ,那么只能移除无效的字符。 google下都是使用正则来移除,其实应该使用高效的位图算法。

类的静态方法:


static bool[] XMLInvalidCharMap = new bool[128];
//[\x00-\x08\x0B\x0C\x0E-\x1F\x26]
for (int i = 0x00; i <= 0x08; i++)
{
XMLInvalidCharMap[i] = true;
}
XMLInvalidCharMap[0x0b] = true;
XMLInvalidCharMap[0x0c] = true;
for (int i = 0x0e; i <= 0x1f; i++)
{
XMLInvalidCharMap[i] = true;
}
//XMLInvalidCharMap[0x26] = true; //&符号,不应该被过滤

使用方法:

       static string ReplaceHexadecimalSymbols(string txt)
{
StringBuilder sb = new StringBuilder();
for (int i = ; i < txt.Length; i++)
{
if (txt[i] < && XMLInvalidCharMap[txt[i]])
{
continue;
}
sb.Append(txt[i]);
}
return sb.ToString();
/*
string r = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]";
return Regex.Replace(txt, r, "", RegexOptions.Compiled);*/
}

http://stackoverflow.com/questions/21053138/c-sharp-hexadecimal-value-0x12-is-an-invalid-character

https://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/

XML hexadecimal value 0x__, is an invalid character的更多相关文章

  1. [Irving]WPF Invalid character in the given encoding. Line xx, position xx.' XML is not valid.

    WPF开发中发现Xaml界面中突然抽风似的提示错误 Invalid character in the given encoding. Line xx, position xx.' XML is not ...

  2. exception 'DOMException' with message 'Invalid Character Error' Php + Mongodb

    问题描述: 项目属于MVC设计模式,技术和框架采用了php5.6 + Yii2.0 + MongoDB. 在我从Controller中调用Model 的 findAll([]) 方法获取数据打印到屏幕 ...

  3. ant导入Zookeeper到Eclipse错误path contains invalid character

    首先在Zookeeper源码目录执行 ant eclipse 遇到错误 path contains invalid character 可以修改\zookeeper\build.xml 文件加入 &l ...

  4. Invalid character found in method name. HTTP method names must be tokens

      o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrenc ...

  5. tomcat 启动报错 Invalid character found in method name. HTTP method names must be tokens

    解决:Invalid character found in method name. HTTP method names must be tokens   阿里云上弄了一个tomcat,经常半夜发送崩 ...

  6. java.lang.IllegalArgumentException: Invalid character found in the request target. The valid charact

    线上环境中部署的 Tomcat 项目,出现部分页面无法打开的情况,但本地环境是好的.经过排查发现,本地 Tomcat版本为 7.0.77,而线上版本为 7.0.88.报错的具体描述为java.lang ...

  7. 异常:Invalid character found in the request target. The valid characters are defined in RFC 3986

    一.背景 事情是这样的,前几天做一个基本的数据库“增删改查”的需求,前端传参的方式是“JSON字符串”,后端接收到此参数后,使用阿里巴巴fastjson进行解析,然后入库.需求很简单吧,但是偏偏遇到问 ...

  8. 终极解决方案: Invalid character found in the request target.

    终极解决方案:(导出可能出现) 我的tomcat版本是8.5.32,导出时遇到以下报错. 报错日志: Invalid character found in the request target. Th ...

  9. Tomcat 8 Invalid character found in the request target. The valid characters are defined in RFC 3986

    终极解决方案: Invalid character found in the request target. The valid characters are defined in RFC 3986 ...

随机推荐

  1. vue 浏览器页面刷新时执行一段代码

    当刷新(浏览器刷新)页面的时候,重置到首页(或其他页面)纯js的是window.onload()但是vue几乎不会用到这个,vue所有的是生命周期那么我们可以根据生命周期来实现这个beforeCrea ...

  2. js 事件创建发布

    // 创建事件. var event = document.createEvent('Event'); // 初始化一个点击事件,可以冒泡,无法被取消 event.initEvent('click', ...

  3. IOS初级:UIwindow

    AppDelegate.h @property (strong, nonatomic) UIWindow *window; AppDelegate.m - (BOOL)application:(UIA ...

  4. tomcat优化(转)

    tomcat优化 Activiti  分享牛  2017-02-08  1132℃ 本文重点讲解tomcat的优化. 基本优化思路: 1.         尽量缩短单个请求的处理时间. 2.      ...

  5. Python Tutor

    Python Tutor Python Tutor 是由 Philip Guo 开发的一个免费教育工具,可帮助学生攻克编程学习中的基础障碍,理解每一行源代码在程序执行时在计算机中的过程.通过这个工具, ...

  6. OneZero第三周第三次站立会议(2016.4.6)

    1. 时间: 13:05--13:15  共计10分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  7. bootstrap表格参数说明

    表格参数: 名称 标签 类型 默认 描述 - data-toggle String ‘table’ 不用写 JavaScript 直接启用表格. classes data-classes String ...

  8. boost-容器

    1.array array相当于是一个增加了STL容器接口的数组,但它不像vector等容器一样可以动态增长,如果需要动态变动array的容量可以使用boost::scoped_array.array ...

  9. sas和ssd盘写入数据效率对比

    表结构如下: CREATE TABLE `tab_AAA` (  `id` bigint(20) NOT NULL AUTO_INCREMENT ,  `customer_no` varchar(32 ...

  10. web-day11

    第11章WEB11-Cookie&Session篇 今日任务 显示用户的上次访问时间 登录系统以后显示商品浏览记录 购买商品将商品添加到购物车 系统登录的验证码的校验 教学导航 教学目标 了解 ...