• 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

ByteArray in XML?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a series of 20 byte values that I'd like to store with some other metatdata in an XML file...
Is this possible without converting the byte[] to a string representation? If I had to convert the bytes to string how can I retrieve the original value?
Thanks very much
Gareth
 
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
There are plenty of byte values that are not valid as XML characters and would cause a parse error - you must convert to a String representation.
You can encode as Hexadecimal where each byte becomes 2 characters or using base64 where 3 bytes become 4 characters and = characters fill out the end if the array size is not evenly divisible by 3.
The Jakarta Apache Commons project - CODEC toolkit has some converters to and from byte[].
Bill
 
Gareth Western
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah great!
The Commons project is brilliant! I should have looked there first. Thanks for pointing that out!
Happy Easter to everyone!
 
reply
    Bookmark Topic Watch Topic
  • New Topic