[jdom-interest] Problem with XMLOutputter beta

stephan.segschneider at snellwilcox.com stephan.segschneider at snellwilcox.com
Thu Jul 5 06:42:11 PDT 2001

Dear JDOM user, Jason and Brett

I have just converted my application back to JDOM beta 6. Using the following
code does solve my problem completely. You can mess up the formatting of an
existing XML file with any text editor (add spaces, add newlines, add tabs
whatsoever) and after loading the XML via SaxBuilder and writing it via the code
shown below you will get everything repaired - formatted the way you expect it -
indentation four spaces, no additional empty lines between elements AND all the
text data *untouched*!

        fileWriter = new FileWriter(location);
        XMLOutputter outputter = new XMLOutputter("    ", true);
        outputter.output(doc, fileWriter);

It would be excellent to have this behaviour in JDOM beta 7 and of course the
final release. I would like other JDOM user to check this out and see if they
agree with me.

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

____________________Reply Separator____________________
Subject:    Re: Re[2]: [jdom-interest] Problem with XMLOutputter beta7#4
Author: "Ken Rune Helland" <kenh at csc.no>
Date:       05/07/01 13:25

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.

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