wood burning stoves 2.0*
The moose likes Web Services and the fly likes Send and Receive Binary Data in XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Send and Receive Binary Data in XML" Watch "Send and Receive Binary Data in XML" New topic
Author

Send and Receive Binary Data in XML

Dharamvir (DV) Punia
Ranch Hand

Joined: Oct 04, 2004
Posts: 34
Hi,
Does anyone have a sample code or reference links on how to send and read binary data in xml. I mean instead of attachment, you can attach files in binary format in xml using base64 to hexadecimal, I cann't use Saaj or axis so I need to put the attachment in xml. Any links or samples would be appreciated.

Thanks,
-DV
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Like how you sting as returntype,use byte[]as return type in ur method/operation
Example
public byte[] GetFileByteArray(String inputfilename){
// code
}


Spritle Software Blogs
Dharamvir (DV) Punia
Ranch Hand

Joined: Oct 04, 2004
Posts: 34
Thanks Balaji. I will try that approach. If you look at the <Data> field in below xml, don't I need to decode it using some kind of base 64 decoder.
Once again tanks for your response.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Yes, binary data must be encoded, typically as base64. Recall that XML has to be Unicode text - there are many binary values that are not valid Unicode characters and will cause a XML parser error.
Bill
Dharamvir (DV) Punia
Ranch Hand

Joined: Oct 04, 2004
Posts: 34
Hi William,
I don't have to worry about encoding here, all I have to worry about is decoding.

This is the scenario: I will receive a post request on a servlet which will have the xml data with binary , so I have to parse the xml document and the node elements, and one of node elements would be binary attachment. What Can I use to decode it, wouldn't Balaji's approach work in this case. If you can, Can you post some links to reference sites or sampes on how to decode it using base64 or anyother way, It doesn't matter what apprach I use, all I care about is getting the binary data.
Thanks,
-DV
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
The Apache Software Foundation Commons project has this CODEC toolkit. It contains classes for handling base64 coded data.
It also has many other goodies you may find useful.
Bill
Dharamvir (DV) Punia
Ranch Hand

Joined: Oct 04, 2004
Posts: 34
Hi William,
Thanks for putting up a reference link for base64 encoder, I will definately look into it.
-DV
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Send and Receive Binary Data in XML
 
Similar Threads
sending binary files to web service
MTOM content transfer - Axis2
Consuming binary data from webservice.
Binary Data using AJAX
Image to String to Image in a email