[jdom-interest] XMLOutputter newline and sockets

Steve Upton steveu at firebrandsoftware.com
Wed Aug 22 13:27:26 PDT 2001

Hi Jason

Thanks for the response. Hmm, interesting one, and unfortunately I agree
with everything you said - I say unfortuately because this way it's harder
find a solution :)

> The default is for newlines not to be added, but the problem is SAX
> doesn't report newlines outside the root element so that results in
> output like:
> <?xml version="1.0"><!-- comment --><root>
>   <child/>
> </root>
> And people don't like that.  They say the file looked like this before
> and I want it to stay that way:
Yep, I can see that, I would too.

> So we add new lines outside the root element.  I agree it's less than
> ideal, but with a few overrides you can get whatever you want.

You can, and in my case the data is small so this would have minimal
performance impact but for a large block of data this means that every
character would have to be checked and the newlines stripped - just for
the sake of a couple in the header - surely the best solution is to not
add them in the first place.

> What's really needed is some tunable output feature that lets you specify
> general output style you want:
> one line
> best effort to round trip
> best effort to beautify
>   using two spaces, four spaces, tabs, etc
> -jh-
Agreed, probably the only thing required at the moment is a 'headerNewlines'
internal flag to determine whether or not there should be newlines in the
block. The problem is what to do about the existing methods, and existing
peoples code.
Clearly the default should be the same as it is now, ie :
    headerNewlines = true
    dataNewlines = false
But what to do about the existing methods, as the setNewlines() method would
not function as expected.

I suspect that the best route would be something along the lines of a

    setFormat(Format myFormat)

Or something similar. The format class could then include the existing
flags, and
new ones could be added without changes to the interface of the XMLOutputter

Thoughts ?


More information about the jdom-interest mailing list