Base64 is an algorithm that is designed for encoding arbitrary sequences of bytes. Each group of three bytes (24 bits) is encoded as four characters taken from a subset of ASCII specifically designed to pass through various gateways and processors intact. The characters are the capital letters AZ, the lowercase letters az, the digits 09, the plus sign (+), the forward slash (/), and the equals sign (=). None of these are likely to cause any problem for XML processors.

The downside to Base64 is that the data is completely opaque . Just because something is an ASCII character in input doesn't mean it's likely to be the same one in output. (In fact, that's almost guaranteed not to happen because Base64 encoding splits the bits of each byte across two bytes in the output.) Here's a typical small Base64 encoded file.


Just looking at it gives you no clue what's hiding in the data. If the data is text, quoted printable will be more transparent. However, for nontext data, such as digital signatures, encrypted content, JPEG images, MP3 recordings, and the like, Base64 is no more opaque than the actual data and is as or more efficient than quoted printable.

Generally the same libraries and tools that know how to encode and decode quoted printable can decode Base64. It's normally just a question of passing the right encoding name to the method call. In addition, in .NET the System.Xml.XmlTextReader and System.Xml.TextWriter classes include built-in support for reading and writing Base64-encoded data.

The downside to encoding in Base64, quoted printable, or any other format is that it increases the size of the data. Base64 increases size by a third in an eight-bit encoding such as UTF-8 and by somewhat more in other encodings like UTF-16. If the data is really large you may well be better off just pointing to the original binary form with a URL as discussed in Item 16 and used in many applications such as XHTML. Alternately, rather than shipping around a single XML document you might choose to ship an archive such as a zip or jar file that contains both the XML document and the supporting binary data. However, if you do need to encode a small amount of non-XML data in a document, Base64 and quoted printable are often convenient , relatively efficient ways to do it.

Effective XML. 50 Specific Ways to Improve Your XML
Effective XML: 50 Specific Ways to Improve Your XML
ISBN: 0321150406
EAN: 2147483647
Year: 2002
Pages: 144 © 2008-2017.
If you may any questions please contact us: