XML hexadecimal value 0x__, is an invalid character
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的更多相关文章
- [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 ...
- exception 'DOMException' with message 'Invalid Character Error' Php + Mongodb
问题描述: 项目属于MVC设计模式,技术和框架采用了php5.6 + Yii2.0 + MongoDB. 在我从Controller中调用Model 的 findAll([]) 方法获取数据打印到屏幕 ...
- ant导入Zookeeper到Eclipse错误path contains invalid character
首先在Zookeeper源码目录执行 ant eclipse 遇到错误 path contains invalid character 可以修改\zookeeper\build.xml 文件加入 &l ...
- 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 ...
- 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,经常半夜发送崩 ...
- java.lang.IllegalArgumentException: Invalid character found in the request target. The valid charact
线上环境中部署的 Tomcat 项目,出现部分页面无法打开的情况,但本地环境是好的.经过排查发现,本地 Tomcat版本为 7.0.77,而线上版本为 7.0.88.报错的具体描述为java.lang ...
- 异常:Invalid character found in the request target. The valid characters are defined in RFC 3986
一.背景 事情是这样的,前几天做一个基本的数据库“增删改查”的需求,前端传参的方式是“JSON字符串”,后端接收到此参数后,使用阿里巴巴fastjson进行解析,然后入库.需求很简单吧,但是偏偏遇到问 ...
- 终极解决方案: Invalid character found in the request target.
终极解决方案:(导出可能出现) 我的tomcat版本是8.5.32,导出时遇到以下报错. 报错日志: Invalid character found in the request target. Th ...
- 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 ...
随机推荐
- NETSHARP微信开发说明
一.微信开发介绍 1.微信分为个人号,订阅号.服务号,需要去理解三个号的区别,对于开发来说也需要了解不同的账号所提供的功能 2.微信号需要审批,审批之后有一些功能才能使用 3.微信提供的功能及使用情况 ...
- 查看tomcat运行日志
1.先到tomcat的logs目录下我这边是:/usr/local/apache-tomcat-7.0.73/logs 2.tail -f catalina.out 3.这样,前端有请求时候,就会输出 ...
- oracle 中删除表 drop delete truncate
oracle 中删除表 drop delete truncate 相同点,使用drop delete truncate 都会删除表中的内容 drop table 表名 delete from 表名 ...
- Bootstrap之Bootstrap组件
一 文本居中 col-xx-offset-xx:水平居中 center-block:使用于不涉及float标签的水平居中,也不涉及列的居中,让哪里居中就写到哪里,本质是:margin:0 auto. ...
- 【转】mysql查看表空间占用情况
${database} 为数据库的名称 /*1.查看索引 (1)单位是GB*/ SELECT CONCAT(ROUND(SUM(index_length)/(**), ), ' GB') AS 'To ...
- 【转】Linux修改SSH端口和禁止Root远程登陆
Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...
- [转]order by 与索引
ORDER BY 通常会有两种实现方法,一个是利用有序索引自动实现,也就是说利用有序索引的有序性就不再另做排序操作了.另一个是把结果选好之后再排序. 用有序索引这种,当然是最快的,不过有一些限制条件, ...
- nginx 下载 大文件被截断
如果出现大文件被截断,且ngix的日志大量出现以下类似报错: 则说明是nginx没有fastcgi_temp的读写权限.其中fastcgi_temp是自己的文件夹名称,每个人的不同且路径也会不同,这个 ...
- Ajax地域选择demo
index.jsp只用于转发到Servlet获得省份数据再转发到province.jsp index.jsp <%@ page language="java" content ...
- 编译时:virtual memory exhausted: Cannot allocate memory,常见于VPS
原文链接:http://blog.csdn.net/taiyang1987912/article/details/41695895 一.问题 当安装虚拟机时系统时没有设置swap大小或设置内存太小,编 ...