Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML + byte array?

Status
Not open for further replies.
If this is a pure XML question I think there's a forum for that. Or are you wanting help specifically on how to do it with Java APIs?

Tim
 
Read the image into a byte[] array.
Then you have two options - put the byte[] array into a CDATA section inside a tag, or encode the byte[] array as Base64, and then add that to a tag's content.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I think you should base64 encode the image data and put that into your XML between appropriate tags. If your just building an XML file you could just write the XML out to file as text and include your image data along with it. If it's a pre-existing XML file that you're inserting data into, you may want to use a DOM API.

Tim
 
What server? You'd use a tag which identifies its contents as Base64 encoded image data.

Tim
 
Base64 data IS a string.
BTW, I really would consider using a CDATA section. Base64 will explode your image file size quite substantially.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
sedj, what are the chances of a byte sequence within the image looking like a CDATA termination string ']]>'? Also, doesn't stuff inside the CDATA still have to conform to the charset of the XML message?

Tim
 
Good points Tim ... not sure on either actually. Perhaps base64 would be better - its just sooooo bloated !

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Agreed [smile]

I tried putting a hash character in a CDATA block and it complained straight away with the default char encoding. I can only image what raw image data would do.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top