[jdom-interest] XMLOutputter indent problems
HUFFMAN BRADLEY S
hip at csa.cs.okstate.edu
Tue May 20 14:11:28 PDT 2003
"Roy van der Kuil" writes:
> I am having problems with writing a previously readed xml-file.
> if I have a file that says:
> <fruits>
> <fruit name="banana"/>
> <fruit name="apple"/>
> </fruits>
>
> And I read it in (using SAXBuilder)
> and after that do an new XMLOutputter(" ", true).output(fruitDocument,
> file);
> I get:
> <fruits>
>
> <fruit name="banana"/>
>
> <fruit name="apple"/>
>
> </fruits>
>
> After re-reading and rewritng that another empty line is added between the
> elements.
>
> I;have replaced the XMLOutputter from beta-9 with the one from beta-8 and
> that fixes the problem.. Any clues?
If you want the file "as read", do
new XMLOutputter().output(fruitDocument, file);
If you want "pretty printing", then in beta 8 do
XMLOutputter outputter = new XMLOutputter();
outputter.setNewLines(true);
outputter.setIndent(" ");
outputter.setTextNormalize();
outputter.output(fruitDocument, file);
In beta 9, use the static method Format.getPrettyFormat() which takes care
of the proper settings for you and reads better
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(fruitDocument, file);
Brad
More information about the jdom-interest
mailing list