xml 十六进制 0X19 是无效字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1325379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
hexadecimal 0X19 is an invalid character
提问by Dominic Mitchell
SO,
所以,
I am building XML string based on the values from the dataset using XMLWriter.
我正在使用 XMLWriter 根据数据集中的值构建 XML 字符串。
It is properly building the xml string as per the settings and the conditions I specified.
它根据我指定的设置和条件正确构建了 xml 字符串。
If there are more than 1000 records in the dataset and when I try to build the xml string I am getting the above error. hexadecimal 0X19 is an invalid character
如果数据集中的记录超过 1000 条,并且当我尝试构建 xml 字符串时,我会收到上述错误。十六进制 0X19 是无效字符
How do I get pass this. I have spent around 6 hrs trying to figure out.
我如何通过这个。我花了大约 6 个小时试图弄清楚。
Please help
请帮忙
回答by Dominic Mitchell
Quite simply, you're not allowed that character in an XML document, no matter how you mark it up. To quote the spec:
很简单,无论您如何标记,都不允许在 XML 文档中使用该字符。引用规范:
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
字符 ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
Roughly translated, that means that before 0x20, you're only allowed tab (0x09), newline (0x0a) and carriage return (0x0d).
粗略地翻译,这意味着在 0x20 之前,您只允许使用制表符 (0x09)、换行符 (0x0a) 和回车符 (0x0d)。
The normal way to overcome this sort of issue to use another, embedded, encoding like base64.
解决此类问题的正常方法是使用另一种嵌入式编码,如base64。
回答by D.Shawley
Hex 0x19 is a control code in the ASCII sequence- it is End of Medium (EM). I'm not sure how it is getting into your data stream. If you are encoding something requiring more than one byte into UTF-8 and then treating it as a single byte character set or some other similar encode/decode sequence, you could be seeing the second byte of a UTF-8 sequence.
Hex 0x19 是ASCII 序列中的控制代码- 它是End of Medium (EM)。我不确定它是如何进入您的数据流的。如果您将需要多个字节的内容编码为 UTF-8,然后将其视为单字节字符集或其他类似的编码/解码序列,您可能会看到 UTF-8 序列的第二个字节。
Are you transcoding from one character set to another? and What are the input and output encodings?
您是否从一种字符集转码到另一种字符集?输入和输出编码是什么?
回答by Sylvain
try 0x19 instead :)
改为尝试 0x19 :)
hexadecimal (base 16) uses 16 symbols which are 0 to 9 and A B C D E F (or a to f, which represents 10 to 15)
十六进制(基数为 16)使用 0 到 9 和 ABCDEF(或 a 到 f,代表 10 到 15)的 16 个符号
0x is just a prefix for numeric constants in programming languages (like C) and shells
0x 只是编程语言(如 C)和 shell 中数字常量的前缀
回答by Kevin Fisher
I've seen similar errors occur with invalid characters in XML tag and/or attribute names. For example, if you don't include a space when manually building up the xml,
我见过类似的错误发生在 XML 标记和/或属性名称中的无效字符上。例如,如果您在手动构建 xml 时不包含空格,
<tagNameattributeName="attributeValue">
would throw an error vs the intended
与预期相比会抛出错误
<tagName attributeName="attributeValue">
Might be worth a look.
可能值得一看。

