[jdom-interest] retrieving the children of an element as text

Jason Hunter jhunter at servlets.com
Wed Sep 13 15:53:22 PDT 2006

J. McConnell wrote:
> On 9/13/06, Jason Hunter <jhunter at servlets.com> wrote:
>> I'd recommend xmlOutputter.outputString(mainelement.getContent()).
> This won't satisfy the OP's goal of mainting the original formatting, 
> will it?

I think it will, since getContent() includes the elements as well as the 
whitespace text nodes, and by default XMLOutputter doesn't alter source 
whitespace.  The call above is very much like what XMLOutputter does 
internally during its recursive descent, and it's pretty good at keeping 
the original formatting.  (I say just "pretty good" because SAX doesn't 
report everything, like whitespace outside the root element, so JDOM 
can't be 100% faithful if you build using SAX.)


More information about the jdom-interest mailing list