• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Send and Receive Binary Data in XML

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William,
Thanks for putting up a reference link for base64 encoder, I will definately look into it.
-DV
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic