[jdom-interest] XMLOutputter line breaks and TextMode.PRESERVE

Rolf Lear jdom at tuis.net
Mon Aug 17 03:03:28 PDT 2009

Hi Christian.

Without digging in to the Textmode.PRESERVE thing... your other options 
are CDATA, and also adding the attribute xml:space="preserve" to the 
<data> element.... like:

<data xml:space="preserve">first line\r\nsecond line</data>


Christian Migowski wrote:
> Hi,
> to my big disappointment I found out that the XMLOutputter when configured with
> xmlSerializer = new
> XMLOutputter(Format.getRawFormat().setExpandEmptyElements(true))
> doubles CR (carriage return) line breaks in the output, i.e. if I have
> an element
> <data>first line\r\nsecond line</data>
> will be outputted as
> <data>first line&#xD;\r\nsecond line</data>
> This results in a double CR if read in again with a different XML
> parser (libxml2 for example).
> I found an explanation in
> http://www.jdom.org/pipermail/jdom-interest/2003-July/012593.html but
> I miss the point in this processing?!
> What does TextMode.PRESERVE - which is the default according to the
> Javadoc - really mean (as it obviously doesn't preserve the text)?
> How can I really preserve the text in elements as-it-is?
> thanks in advance & best regards,
> christian

More information about the jdom-interest mailing list