Why can’t binary data be represented directly in XML, for example, by representing it as Unicode
byte values? XML elements can carry strings represented as base64. Discuss the advantages or
disadvantages of using this method to represent binary data.
What will be an ideal response?
Binary data can’t be represented directly in XML, because somewhere the embedded binary data will include
the representation of a special character such as '<' or '>'.
Even if binary is represented as CDATA, it might include the terminator for CDATA: ']]'.
Binary data can be encoded in base64 and represented in XML as a string.
Base64 encoding takes three bytes, each consisting of eight bits, and represents them as four printable
characters in the ASCII standard (padding when necessary).
Thus a disadvantage in using base64 is that the quantity of data is increased by a factor of 4/3 and the
translation process at both ends can take time. In addition, the encoded value isn’t really a string and in some
cases may be passed on to an application as a string.
The only advantage of base64 is that it can be used when necessary. It is in fact used in XML Security to
represent digital signatures and encrypted data. In both cases, the data is enclosed in elements that specify, for
example, signature or encrypted data.