[jdom-interest] Problem with XMLOutputter beta

Jason Hunter jhunter at acm.org
Thu Jul 5 10:38:51 PDT 2001

stephan.segschneider at snellwilcox.com wrote:
> 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.setTrimText(false);
>         outputter.setExpandEmptyElements(false);
>         outputter.output(doc, fileWriter);

Pretty formatting is done by adding and removing text whitespace -- so I
don't see how you can say everything's formatted nicely and text data is
untouched.  Some text nodes are definitely being touched.  Given the
flags above you're adding whitespace without ever removing any, so a
pretty printed document read in and output this way will be whitespace
padded even tho it's not necessary.


More information about the jdom-interest mailing list