C#十六进制值0x12,是一个无效字符 - 程序园
这是ASCII表。有128个符号
这是一些小的测试代码,它会添加ASCII表中的每个符号,并尝试将其作为XML文档加载。
static public void RegexTry()
{
StreamReader stream = new StreamReader(@"test.xml");
string xmlfile = stream.ReadToEnd();
stream.Close(); string text = ""; for (int i = 0; i < 128; i++ )
{
char t = (char) i; text = xmlfile.Replace('П', t); XmlDocument xml = new XmlDocument();
try
{
xml.LoadXml(text);
}
catch (Exception ex)
{
Console.WriteLine("Char("+i.ToString() +"): " + t + " => error! " + ex.Message);
continue;
} Console.WriteLine("Char(" + i.ToString() + "): " + t + " => fine!");
} Console.ReadKey();
}
因此,它返回:
Char(0): => error! '.', hexadecimal value 0x00, is an invalid character. Line 5, position 7.
Char(1): => error! '', hexadecimal value 0x01, is an invalid character. Line 5, position 7.
Char(2): => error! '', hexadecimal value 0x02, is an invalid character. Line 5, position 7.
Char(3): => error! '', hexadecimal value 0x03, is an invalid character. Line 5, position 7.
Char(4): => error! '', hexadecimal value 0x04, is an invalid character. Line 5, position 7.
Char(5): => error! '', hexadecimal value 0x05, is an invalid character. Line 5, position 7.
Char(6): => error! '', hexadecimal value 0x06, is an invalid character. Line 5, position 7.
Char(7): => error! '', hexadecimal value 0x07, is an invalid character. Line 5, position 7.
Char(8): => error! '', hexadecimal value 0x08, is an invalid character. Line 5, position 7.
Char(9): => fine!
Char(10):
=> fine!
Char(11): => error! '', hexadecimal value 0x0B, is an invalid character. Line 5, position 7.
Char(12): => error! '', hexadecimal value 0x0C, is an invalid character. Line 5, position 7.
Char(13):
=> fine!
Char(14): => error! '', hexadecimal value 0x0E, is an invalid character. Line 5, position 7.
Char(15): => error! '', hexadecimal value 0x0F, is an invalid character. Line 5, position 7.
Char(16): => error! '', hexadecimal value 0x10, is an invalid character. Line 5, position 7.
Char(17): => error! '', hexadecimal value 0x11, is an invalid character. Line 5, position 7.
Char(18): => error! '', hexadecimal value 0x12, is an invalid character. Line 5, position 7.
Char(19): => error! '', hexadecimal value 0x13, is an invalid character. Line 5, position 7.
Char(20): => error! '', hexadecimal value 0x14, is an invalid character. Line 5, position 7.
Char(21): => error! '', hexadecimal value 0x15, is an invalid character. Line 5, position 7.
Char(22): => error! '', hexadecimal value 0x16, is an invalid character. Line 5, position 7.
Char(23): => error! '', hexadecimal value 0x17, is an invalid character. Line 5, position 7.
Char(24): => error! '', hexadecimal value 0x18, is an invalid character. Line 5, position 7.
Char(25): => error! '', hexadecimal value 0x19, is an invalid character. Line 5, position 7.
Char(26): => error! '', hexadecimal value 0x1A, is an invalid character. Line 5, position 7.
Char(27): => error! '', hexadecimal value 0x1B, is an invalid character. Line 5, position 7.
Char(28): => error! '', hexadecimal value 0x1C, is an invalid character. Line 5, position 7.
Char(29): => error! '', hexadecimal value 0x1D, is an invalid character. Line 5, position 7.
Char(30): => error! '', hexadecimal value 0x1E, is an invalid character. Line 5, position 7.
Char(31): => error! '', hexadecimal value 0x1F, is an invalid character. Line 5, position 7.
Char(32): => fine!
Char(33): ! => fine!
Char(34): " => fine!
Char(35): # => fine!
Char(36): $ => fine!
Char(37): % => fine!
Char(38): => error! An error occurred while parsing EntityName. Line 5, position 8.
Char(39): ' => fine!
Char(40): ( => fine!
Char(41): ) => fine!
Char(42): * => fine!
Char(43): + => fine!
Char(44): , => fine!
Char(45): - => fine!
Char(46): . => fine!
Char(47): / => fine!
Char(48): 0 => fine!
Char(49): 1 => fine!
Char(50): 2 => fine!
Char(51): 3 => fine!
Char(52): 4 => fine!
Char(53): 5 => fine!
Char(54): 6 => fine!
Char(55): 7 => fine!
Char(56): 8 => fine!
Char(57): 9 => fine!
Char(58): : => fine!
Char(59): ; => fine!
Char(60): => error! The '<' character, hexadecimal value 0x3C, cannot be included in a name. Line 5, position 13.
Char(61): = => fine!
Char(62): > => fine!
Char(63): ? => fine!
Char(64): @ => fine!
Char(65): A => fine!
Char(66): B => fine!
Char(67): C => fine!
Char(68): D => fine!
Char(69): E => fine!
Char(70): F => fine!
Char(71): G => fine!
Char(72): H => fine!
Char(73): I => fine!
Char(74): J => fine!
Char(75): K => fine!
Char(76): L => fine!
Char(77): M => fine!
Char(78): N => fine!
Char(79): O => fine!
Char(80): P => fine!
Char(81): Q => fine!
Char(82): R => fine!
Char(83): S => fine!
Char(84): T => fine!
Char(85): U => fine!
Char(86): V => fine!
Char(87): W => fine!
Char(88): X => fine!
Char(89): Y => fine!
Char(90): Z => fine!
Char(91): [ => fine!
Char(92): \ => fine!
Char(93): ] => fine!
Char(94): ^ => fine!
Char(95): _ => fine!
Char(96): ` => fine!
Char(97): a => fine!
Char(98): b => fine!
Char(99): c => fine!
Char(100): d => fine!
Char(101): e => fine!
Char(102): f => fine!
Char(103): g => fine!
Char(104): h => fine!
Char(105): i => fine!
Char(106): j => fine!
Char(107): k => fine!
Char(108): l => fine!
Char(109): m => fine!
Char(110): n => fine!
Char(111): o => fine!
Char(112): p => fine!
Char(113): q => fine!
Char(114): r => fine!
Char(115): s => fine!
Char(116): t => fine!
Char(117): u => fine!
Char(118): v => fine!
Char(119): w => fine!
Char(120): x => fine!
Char(121): y => fine!
Char(122): z => fine!
Char(123): { => fine!
Char(124): | => fine!
Char(125): } => fine!
Char(126): ~ => fine!
Char(127): => fine!
你可以看到有很多不符合XML代码的符号。要替换它们,我们可以使用Reqex.Replace
static string ReplaceHexadecimalSymbols(string txt)
{
string r = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]";
return Regex.Replace(txt, r,"",RegexOptions.Compiled);
}
C#十六进制值0x12,是一个无效字符 - 程序园的更多相关文章
- [No0000133]c# ERROR:“.”(十六进制值 0x00)是无效的字符
December 24, 2013 c# exception “.”(十六进制值 0x00)是无效的字符. 解决方法:常见于socket方式连接(包括HTTP方式)等.报文交互时候,对方会在字符串后面 ...
- XML 十六进制值 是无效的字符错误 解决方法之一 转
/// <summary> /// 过滤非打印字符 /// </summary> /// <param name="tmp">待过滤</p ...
- 调用webservice接口,报错:(十六进制值0x01)是无效的字符
#事故现场 调用webservice接口,报错:(十六进制值0x01)是无效的字符. 如图: 意思是webservice返回的信息中包含无效的字符,无法解析成xml: #分析 使用postman向we ...
- (C++)读取一个输入的int型十进制数字的位数,并正序输出每个位上的值(不同数位的值用1个空格字符间隔)
1 /* 2 程序功能:读取一个输入的int型十进制数字的位数,并正序输出每个位上的值(不同数位的值用1个空格字符间隔). 3 例如:当输入985这个数字时,显示如下信息: 4 985是一个3位数字! ...
- MySql_十六进制值
十六进制值 MySQL支持十六进制值.在数字上下文中,十六进制数如同整数(64位精度).在字符串上下文,如同二进制字符串,每对十六进制数字被转换为一个字符: mysql> SELECT x'4D ...
- ibatis 参数错误,无效字符
--- The error occurred in EmptyMapping.xml. --- The error occurred while applying a parameter map. - ...
- windows无效字符名导致的错误及解决办法
今天用file_put_content($fileName,$data)产生错误:内容如下: Warning: file_put_contents(images/7d5636992a7395f9174 ...
- ORA-00911:无效字符错误
ORA-00911:无效字符错误--造成构建环境的一个小错误 实施某功能脚本语句.编译时,出现了ORA-00911错误,当时有些疑惑,之前生产库使用是没有问题的,经过一番检查后发现原来是一个非常细微的 ...
- 解决错误:此用户名包含无效字符,请输入有效的用户名。wordpress不能注册中文用户名的问题
wordpress在默认情况下不支持中文用户名,就是在后台添加用户的时候,如果用户名包含中文,则显示”错误:此用户名包含无效字符,请输入有效的用户名.”如何解决这个问题呢? 不用插件的话就需要修改一个 ...
随机推荐
- 一个线上Java空指针问题的排查经过
某天,运营反馈,某商品下单异常 1.原来是一个空指针报错 根据用户输入的下单关键信息搜索日志系统看到如下报错 stackTrace: "java.lang.NullPointerExcept ...
- Java中创建String的两道面试题及详解
我们知道创建一个String类型的变量一般有以下两种方法: String str1 = "abcd"; String str2 = new String("abcd&qu ...
- 去BAT面试完的Mysql面试题总结(55道,带完整答案)
1.一张表里面有ID自增主键,当insert了17条记录之后,删除了第15,16,17条记录,再把mysql重启,再insert一条记录,这条记录的ID是18还是15 ? 2.mysql的技术特点是什 ...
- 【题解】Tom的烦恼
题目描述 Tom是一个非常有创业精神的人,由于大学学的是汽车制造专业,所以毕业后他用有限的资金开了一家汽车零件加工厂,专门为汽车制造商制造零件.由于资金有限,他只能先购买一台加工机器.现在他却遇到了麻 ...
- servlet的ServletConfig接口
ServletConfig接口 A servlet configuration object used by a servlet container to pass information to a ...
- 【mysql升级步骤】windows mysql版本升级 ,mysql 5.6 升级到5.7.27
最近博主由于工作原因需要把之前安装好的的mysql 5.6.44版本卸载,然后安装mysql 5.7.*版本. 前提:为什么要升级到5.7版本? 因为博主在5.6版本上执行脚本时候报出异常:to yo ...
- python re.I compile search
import restring = "The quick brown fox jumps over the lazy dog."a_list = string.split()pat ...
- Codeforces 1148F Foo Fighters 贪心
题意:给你若干个数对,每个数对有两个属性,一个属性是权值,一个属性是位标志,假设这些数对的的权值和是sum,你可以选择一个二进制数s,与所有的数对的位标志按位与,如果按位与之后的位标志有奇数个1,那么 ...
- java多线程面试题选择题大全含答案
v java多线程面试题选择题大全含答案 java多线程面试题选择题大全含答案 1.下面程序的运行结果()(选择一项)public static void main(String[] args) {T ...
- informix 计算 日期之差
原文地址:http://blog.chinaunix.net/uid-678894-id-3138829.html https://blog.csdn.net/zhengqiqiqinqin/arti ...