[jdom-interest] round trip XML

Brad Morgan Brad.Morgan at e-pubcorp.com
Tue Oct 17 09:08:19 PDT 2000


I agree with you on the constructor issue.  I think adding the new ones is
upwardly compatible thing to do, but I'm acceptable to removing all but the
default as well.  Either change produces a more consistant interface.  The
current set of constructors seems lacking in consistancy given the ways in
which people are tending to use them (pick a constructor that almost does
what you want, then fine tune with methods).

Brad Morgan
e-Publishing Corp.

Email: Brad.Morgan at e-pubcorp.com
Phone: (719)593-7377 x35
Fax: (719)593-2996

e-Publishing Corp. is a BroadVision company
URL: http://www.e-pubcorp.com

-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Alex Chaffee
Sent: Monday, October 16, 2000 3:58 PM
To: Patrick Dowler
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] round trip XML

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

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

On reflection, maybe there should be a constructor

XMLOutputter(boolean trimText, boolean newlines, boolean indent)

So you can simply call

new XMLOutputter(false,false,false)

for the first case,

new XMLOutputter(true,true,true)

for the second, and

new XMLOutputter(true,false,false)

for the most compact representation.

> (1) if the newlines==true, I get an extra blank line except after the
> DocType, ie:
> <?xml version="1.0" encoding="UTF-8"?>
> <foo>
>   <bar/>
> </foo>
> This is because the "\n"s in the xml file are kept as separate Elements

text nodes, not Elements

> in the Document, presumably.

Yes, and since the whitespace between the doctype and the first (root)
element is effectively stripped, since there's no place for a text
child of Document (only comments, PIs, and a single element).  I

> RFE: Maybe the outputter could add a newline after the DocType anyway,
> or this could be turned on as distinct from the newlines arg/setting?

No, that's not necessary.

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/
To control your jdom-interest membership:

More information about the jdom-interest mailing list