[jdom-interest] round trip XML

Patrick Dowler Patrick.Dowler at nrc.ca
Mon Oct 16 16:55:11 PDT 2000

On Mon, 16 Oct 2000, you wrote:
> That's what the new method setTrimText(true) is for.  The idea is:
> either you 
>  - pass whitespace through unchanged, and turn off newlines and indent
>  - or strip it with trimText, and turn on newlines and indent

OK - I just failed to grok that method when I scanned the docs. Thanks.

Should there be a similar method in SAXBuilder for reading docs where
one knows newlines are meaningless - I have larg-ish data docs that
have elements with either children or text content and whitespace is
always irrelevant excepty for readability. I'd like to silently avoid the
thousands of extra String("\n") that would be included with things like


That is, if I read a pretty XML file, I know I don't want the (3?) strings of
"\n" in the content list - even if the strings are interned, that is still 3
LinkedList nodes referencing them/it.

> I'm reluctant to add this property to the constructor, since it's a
> slippery slope.  In fact, I'd like to strip all but the default
> constructor, but I can see how some find the extra constructors
> useful.
> On reflection, maybe there should be a constructor
> XMLOutputter(boolean trimText, boolean newlines, boolean indent)

The indent art is currently a String (typically "   " or "").

I'm not that keen on method signatures like (boolean,boolean,boolean)
since it is always hard to recall what order things are in. Something
like (int,int) is OK for position because everyone takes it as (x,y).

For convenience of writing the code, it seems that 

	XMLOutputter(boolean pretty)

would suffice. If someone wants to actually tune the output precisely, making a
few method calls is not too much to ask. Maybe pretty would give trimText,
newlines, indent of 2-4 spaces, and a line-break after 80 chars. 


Patrick Dowler
Canadian Astronomy Data Centre

More information about the jdom-interest mailing list