wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 12760
    
    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!
 
jQuery in Action, 2nd edition
 
subject: ByteArray in XML?
 
Similar Threads
Xml Element to Byte Array
writing byte array into a file
Writing byte array to xml in Java
Convert byte to its hex format?
Saving a byteArray in XML and retrieving it in Java