[jdom-interest] Problem with XMLOutputter beta7#4

Ken Rune Helland kenh at csc.no
Thu Jul 5 05:25:37 PDT 2001

We used to have a trim option but i tink normalize replced this.

I think we woud need a trim option that only trims whitespace
at the beginnin and end of the text as to give a opportunity to
roundtripp the XML where some whitespace is relevant.

Or maybe a mask for what witespace to trim?


> 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 application.
> To see what I mean have a look at the following example (best viewed
> with a proportional font):
> <Root>
>     <Dialog>
>         <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
> line.</Comment>
>         <Widget label="widget 1"/>
>         <Widget label="widget 2"/>
>         <Widget label="widget 3"/>
>     </Dialog>
> </Root>
> 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 untouched)
> 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.
>  Cheers,
>                Stephan
> -----------------------------------------------------------------
>   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.

More information about the jdom-interest mailing list