[jdom-interest] String utilities for JDOM?

guru at stinky.com guru at stinky.com
Tue Jul 3 12:44:00 PDT 2001


On Tue, Jul 03, 2001 at 12:20:56PM -0400, Jon Baer wrote:
> 
> I need to write out Elements back in there original form and was
> wondering if its possible without an XMLOutputter, say
> element.toString() = <element foo="bar">value</element>

Why don't you want an XMLOutputter?

toString() is meant for debugging.  It may include other information
than the XML content of an element.  It definitely shouldn't recurse
into child elements, since that exposes debug output to bugs like
infinite loops, and performance hits in objects other than itself.

Element used to have toSerializedForm but it was removed because
there's more than one way to skin a cat, or output XML, and it was
decided that rather than decide for you, we would just allow you to
choose by initializing an XMLOutputter with your preferred options.

What you want is achievable by the following code:

new XMLOutputter().outputString(element)

Making a new XMLOutputter is an extremely efficient operation since
there are no complex data structures, only flags and Strings (set to
constants).

> Also Im in the middle of doing somethere where Id like to try to keep
> Elements locked inside a Map and wanted to see if there was a
> performance factor between keeping the Element in the map rather than
> say keeping the String value and having to rebuild the Document again.
> Any ideas?

Reparsing a document is really slow.  I'd save the Elements, assuming
you have enough memory.

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