XMLOutputter line breaks and TextMode.PRESERVE

View: New views
2 Messages — Rating Filter:   Alert me  

XMLOutputter line breaks and TextMode.PRESERVE

by chrismfwrd :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 \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
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

Re: XMLOutputter line breaks and TextMode.PRESERVE

by Rolf Lear-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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>


Rolf

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 \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
>  

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...