[jdom-interest] Problem with XMLOutputter beta7#4

stephan.segschneider at snellwilcox.com stephan.segschneider at snellwilcox.com
Thu Jul 5 04:12:49 PDT 2001

Hi again

Thanks Alex for your reply. I had some more tests and unfortunately I
encountered a big problem.
Yes - setTextNormalize(true) will give me a proper output regarding the
indentation of elements BUT - and that's a very big BUT - it destroys all my
line breaks in my own Comment elements as well. This is not acceptable for my
To see what I mean have a look at the following example (best viewed with a
proportional font):

        <Comment>This is the first line of my comment.
And this is the second line of my comment.

This is a third line with an empty line between the second and third
        <Widget label="widget 1"/>
        <Widget label="widget 2"/>
        <Widget label="widget 3"/>
If I use setTextNormalize(true) in the above example my Comment will loose all
spaces and new lines! The Comment elements are essential for the user and they
need to edit and view them via my applications text editor (basically a
specialised XML-editor). BTW the XML files for my application are partially
created automatically and obviously elements and comments get added by the user
as well.

So the question is: Why is the text content of an element processed as well by
the setTextNormalize method? (This is part of the data and should kept
Do I totally misunderstand the concept and is there a solution for my problem?
I need the formatting in my element text content but I also need a proper
formatted XML file!

A solution to my problem is essential and any help is appreciated.


  Stephan Segschneider
  EMail : stephan.segschneider at snellwilcox.com  (office)

____________________Reply Separator____________________
Subject:    Re: [jdom-interest] Problem with XMLOutputter beta7#4
Author: "Alex Chaffee" <alex at jguru.com>
Date:       04/07/01 18:12

stephan.segschneider at snellwilcox.com wrote:

>        outputter.setTextNormalize(false);
That's your problem. I bet you scanned this document in from a text 
file. The parser, and JDOM, preserve all the whitespace they can from 
the original file. Then, in *addition* to that whitespace, it does its 
own indenting & newlines. Try setting textNormalize to true and the 
spurious whitespace will be stripped first.

>I have tried every setting forward and backwards but I cant get it to work. It
>worked fine in beta 6.
However, this is mysterious. If if persists, please send a snippet of 
the original file and the output.

You should also try setIndent("X"). That will tell you for sure which 
spaces are being added by XMLOutputter (the X's) and which are from the 
original document.

Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/

The contents of this communication are confidential to the normal user of
the email address to which it was sent.  If you have received this email
in error, any use, dissemination, forwarding, printing or copying of this
email is strictly prohibited.  If this is the case, please notify the sender
and delete this message.

More information about the jdom-interest mailing list