Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB outputting invalid XML when data contains non-displayable chars

I'm using JAXB 2.2.5 to output Xml from a JAXB Model, the data is populated from the database and occasionally the database contains non-displayable characters that it should not such as

0x1a 

If it does then JAXB outputs invalid Xml by just outputting this char as is, shouldn't it escape it or something ?

Update

I wonder if there are any implementations that do fix this problem, maybe Eclipselink MOXy does ?

EDIT

I tried the workaround that fixes the illegal char issue however it changes the output in an undesirable way.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><metadata created="2013-02-27T11:40:04.009Z" xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0"><cdstub-list count="1" offset="0"><cdstub id="w237dKURKperVfmckD5b_xo8BO8-" ext:score="100"><title>fred</title><artist></artist><track-list count="5"/></cdstub></cdstub-list></metadata>

to

<?xml version="1.0" ?><metadata xmlns:ext="http://musicbrainz.org/ns/ext#-2.0" xmlns="http://musicbrainz.org/ns/mmd-2.0#" created="2013-02-27T11:39:15.394Z"><cdstub-list count="1" offset="0"><cdstub id="w237dKURKperVfmckD5b_xo8BO8-" ext:score="100"><title>fred</title><artist></artist><track-list count="5"></track-list></cdstub></cdstub-list></metadata>

i.e <track-list count="5"/> has become <track-list count="5"></track-list>which is undesirable, I'm not sure why it is doing this.

like image 294
Paul Taylor Avatar asked Nov 05 '12 10:11

Paul Taylor


1 Answers

It is apparently a common problem - and marked as a bug JAXB generates illegal XML characters.

You can find a workaround at Escape illegal characters

like image 64
thedayofcondor Avatar answered Sep 18 '22 12:09

thedayofcondor