• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ByteArray in XML?

 
Gareth Western
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic