[jdom-interest] raw bytes turned into string and inserted into xml

Bart Read bart at wdi.co.uk
Mon Mar 18 07:21:25 PST 2002


Jeff,


Try using base 64 encoding on your input.  Base 64 encoding uses only
printable ASCII characters, all of which are legal in XML.  When you want to
get back to the raw output simply base 64 decode your element content /
attribute value (whichever contains the base 64 encoded binary data).  Check
the following URL:

http://www.freesoft.org/CIE/RFC/2065/56.htm

This describes base 64 encoding and should enable you to develop a simple
encoding / decoding class.  I'd give you the source code for ours, but it's
copyrighted so I can't -- it's not difficult to do anyway.

Sun do actually provide one with the JDK but the thing is that it's in the
com.sun package so it's not guaranteed to be in future releases so you're
better off writing your own.


Cheers,
Bart



=================================
Bart Read
Senior Developer
Abbotsbury Software Ltd
Abbotsbury, DORSET DT3 4JT
Tel: +44 (0) 1305 871543
E-mail: bart at wdi.co.uk
=================================
----- Original Message -----
From: "Jeff Singer" <jeff.singer at vine.co.za>
To: <jdom-interest at jdom.org>
Sent: Monday, March 18, 2002 2:47 PM
Subject: [jdom-interest] raw bytes turned into string and inserted into xml


> Hi all,
>
> I have a situation in which my applications input is a raw stream of
> bytes, these bytes are actually ascii strings which occassionaly will
> contain characters which are illegal to xml like 0x4, 0x0, 0x1 - quite a
> few in this range. I use the string constructor which takes an encoding
> to form them into java.lang.String objects. This works fine, I then
> insert them as content onto a JDOM Element object and eventually after
> building up my document I use an XMLOutputter to convert the DOM to an
> XML string. This also works fine, where the problem lies is when the app
> that accepts the xml string I have generated tries to parse the xml. It
> throws JDOMException because the xml contains an invalid xml character
> in xml's that were created from byte streams which contained characters
> in the range already mentioned.
>
>
> Sample App attached
>
> Any help/ideas would be appreciated.
>
> Thanks in advance
> Jeff Singer




---------- Automatically inserted by WDI Mailserver ----------------
This message has been scanned for virus, trojans, illegal relays and
spam. If you have any comments, problems or questions please do not
hesitate to contact:
Abbotsbury Software Ltd
Tel: +44 1305 871543 Fax: +44 1305 871688
Email: postmaster at wdi.co.uk
Web: http://www.wdi.co.uk/virus.phtml



More information about the jdom-interest mailing list