在 XML 中存储值 NUL (ASCII) [英] Storing the value NUL (ASCII) in XML
问题描述
是否可以像这样在 XML 中保存 ASCII NUL 字符 *NUL**NUL**NUL*
?
Is it possible to save the ASCII NUL character in XML like this <data>*NUL**NUL**NUL*</data>
?
我知道我可以使用 System.out.println("\0")
在 Java 中显示这个值,我想知道 XML 是否可以处理这个值.
I know I can display this value in Java using System.out.println("\0")
and I wonder if XML can handle this value.
*我的目标是使用 Java 从 XML 中获取\0\0\0"
*My objective is to get "\0\0\0" from XML using Java
先谢谢你!
推荐答案
来自 规范 1.0 官方不允许.
ASCII NUL 又名 '\0'
又名 \u0000
是 java 中的一个普通字符.然而,在 C/C++ 中,它被用作字符串终止符.因此,当 C 软件处理 XML 时,它可能会过早地检测到 XML 文本的结尾.
The ASCII NUL aka '\0'
aka \u0000
is a normal character in java. In C/C++ however it is used as a string terminator. So when C software would process XML it probably would detect the end of the XML text way too early.
对于这个java也有一个解决方案,即当XML以UTF-8编码写入时,Unicode值> 127以第8位为1的多字节序列编码.DataOutputStream.writeUTF8
写入'\0` 也作为多字节序列.所以读取正常,解码正常.
For this java also has a solution, namely when XML is written in the UTF-8 encoding Unicode values > 127 are encoded in a multibyte sequence with 8th bit 1. DataOutputStream.writeUTF8
writes the '\0` also as multi-byte sequence. So it is read normally, and the decoding works.
- 这不是要求最短编码的完全严格的 UTF-8.
- 我仍然不确定处理 XML DOM 的 C 语言错误.
- This is not entirely strict UTF-8 that requires the shortest encoding.
- I am still unsure about errors in C of processing the XML DOM.
所以这不是一个好主意.
So it is not a good idea.
另外请注意,二进制数据应该转换为 Base64 ASCII.因为 UTF-8 不适合二进制数据.
Also mind, binary data should be converted to Base64 ASCII instead. As UTF-8 is not suited for binary data.
这篇关于在 XML 中存储值 NUL (ASCII)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!