This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Send and Receive Binary Data in XML

 
Dharamvir (DV) Punia
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like how you sting as returntype,use byte[]as return type in ur method/operation
Example
public byte[] GetFileByteArray(String inputfilename){
// code
}
 
Dharamvir (DV) Punia
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic