How do I embed eXcel documents or Word documents in XML? I understand that XML is text format but is there a way to encode the binaries into some format like how email attach binary image files as a multipart mime attribute?

Peter Ciuffetti

The technique I've seen used is to convert the binary file (any type) into Base64. This converts every three binary bytes into a four-character ascii string. The file encoded in this fashion is therefore only 25% bigger than the original file. And its relatively easy to encode and decode.

The ascii characters used by the encoding are all valid XML text node characters so you don't even need to use CDATA sections. You can simply place the encoded result inside an element and the file will be well-formed. The encoding is described by RFCs 1421 and RFC 2045.

See http://info.internet.isi.edu/in-notes/rfc/files/rfc2045.txt (section 6.8)

The W3C has a Java tool for encoding and decoding base64 which is part of their DSig project.

See http://www.w3.org/PICS/refcode/Parser/javadocs/Package-w3c.tools.codec.html for the API and http://www.w3.org/PICS/refcode/Parser/ for information about obtaining the tools.