aspose file tools*
The moose likes XML and Related Technologies and the fly likes ByteArray in XML? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "ByteArray in XML?" Watch "ByteArray in XML?" New topic
Author

ByteArray in XML?

Gareth Western
Ranch Hand

Joined: Apr 07, 2004
Posts: 45
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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Apr 07, 2004
Posts: 45
Ah great!
The Commons project is brilliant! I should have looked there first. Thanks for pointing that out!
Happy Easter to everyone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ByteArray in XML?