[jdom-interest] round trip XML

Alex Chaffee guru at edamame.stinky.com
Mon Oct 16 14:57:45 PDT 2000


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
useful.

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
think.


> 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/



More information about the jdom-interest mailing list