How do you embed binary data in XML?

Bill the Lizard picture Bill the Lizard · Aug 21, 2008 · Viewed 106.9k times · Source

I have two applications written in Java that communicate with each other using XML messages over the network. I'm using a SAX parser at the receiving end to get the data back out of the messages. One of the requirements is to embed binary data in an XML message, but SAX doesn't like this. Does anyone know how to do this?

UPDATE: I got this working with the Base64 class from the apache commons codec library, in case anyone else is trying something similar.

Answer

Greg Hurlman picture Greg Hurlman · Aug 21, 2008

You could encode the binary data using base64 and put it into a Base64 element; the below article is a pretty good one on the subject.

Handling Binary Data in XML Documents