This is an example XML file that would come from the Android Client.
<test>
<to>Mee</to>
<from>Youuu</from>
<img src="http://www.domain.com/path/to/my/image.jpg" />
</test>
I have written a XML parser about this. My problem is while passing it to the Android Client, I need to have the image binary data instead of the image path. How can I accomplish this and how can I update the above said XML with the binary data.
You could use Base64 to encode your image binary data (represented by a
byte[]) and include it in the xml as CDATA.Then on the Android machine, you just decode it to a byte array, and render the image.
You can use Apache Commons to encode/decode.
Edit:
You need to get a byte representation of the image data in order to convert it. See my example. This is using
sun.misc.BASE64Decoderandsun.misc.BASE64Encoder, you may need to adapt depending on what you have at your disposal on Android (see Apache Commons).Then you have your image data as a string in
imgBase64, you just have to append a node to your xml using the DOM implementation you want, for example dom4j. There are methods to addCDATAto the XML. Finally, on your Android, you just need to retrieve the node content and you’re good to decode it like above and do what you want with the image.