Is it possible to save the ASCII NUL character in XML like this <data>*NUL**NUL**NUL*</data>
?
I know I can display this value in Java using System.out.println("\0")
and I wonder if XML can handle this value.
*My objective is to get "\0\0\0" from XML using Java
Thank you in advance!
By the specs for 1.0 it would not be allowed officially.
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.
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.
So it is not a good idea.
Also mind, binary data should be converted to Base64 ASCII instead. As UTF-8 is not suited for binary data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With