[jdom-interest] XMLOutputter behavior
guru at stinky.com
guru at stinky.com
Sun Jun 17 06:39:38 PDT 2001
On Sat, Jun 16, 2001 at 01:03:40PM -0700, Jason Hunter wrote:
> guru at stinky.com wrote:
> > One problem is, the default (no-frills) XMLOutputter outputs a newline
> > at the very end of the document. But the Javadoc says it adds *no*
> > line breaks. I'd like to change it so it outputs no trailing newline.
> > Is anyone depending on that final line break?
> Right now we're adding new lines after the decl, after the doctype, and
> after the last node. We do this always. This is because when build
> with a SAX parser JDOM is not told about whitespace outside the root
> element, nor could JDOM hold the whitespace in its object model, so
> without those new lines the output would have no whitespace outside the
> root, and that's not how most people write their documents.
> Having setNewlines() trigger the newlines is insufficient because for
> round tripping you want to preserve the same whitespace in the file.
> You don't want to add new lines in the root to get newlines outside the
OK, but do we really want *two* closing newlines when setNewlines is
> It may be appropriate to have another set method that could turn off the
> extra newlines.
One for each? Or three binary flags? I'm thinking
public static final int NEWLINES_DECLARATION = 1
public static final int NEWLINES_DOCTYPE = 2
public static final int NEWLINES_ENDOFDOCUMENT = 4
outputter.setExtraNewlines(NEWLINES_DECLARATION | NEWLINES_ENDOFDOCUMENT)
(Low priority, naturally, but I might get around to it.)
BTW, I'm also adding a comment that no matter what the value of
lineSeparator is, newlines embedded inside text nodes will be printed
verbatim -- they're not converted from \n to \r\n, e.g.
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/
More information about the jdom-interest