[jdom-interest] XMLOutputter behavior

Jason Hunter jhunter at collab.net
Sat Jun 16 13:03:40 PDT 2001

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

It may be appropriate to have another set method that could turn off the
extra newlines.


More information about the jdom-interest mailing list