[jdom-interest] getSerializedForm() [eg]

Rosen, Alex arosen at silverstream.com
Wed Apr 25 08:31:45 PDT 2001

My only requirement is that there is a very easy way to print out an XML tree
(a Document or Element) in an easy-to-read format. When I'm debugging an XML
problem, I want to sprinkle printouts throughout my code to dump the XML at the
current stage. This really wants to be a single line of code, to make this
process nice, IMO. I could imagine that this could be implemented as one or
more static methods on XMLOutputter or a DebugHelper or something, if
toString() is the wrong place. I don't care if this prints out useable XML, or
if it prints out [JDOM Element: <xml here>], because this is just for
debugging, not for actually using. We should try to make the output be readable
(i.e. pretty printed), no matter what the internal formatting of the XML is
(like XMLOutputter 1.40 claims to do). There could also be a version that
prints exactly what the XML will look like, though that might be harder to

I see no useful value in getSerializedForm(). For the actual running code of
your program, having to write a few lines of code to use XMLOutputter is not
too much of a burden, if it is an better API and causes less problems.

> toString is mostly for debugging.  The implementation should represent all
> useful internal state, not just what happens to have an XML form.

I think that printing out internal state would be useful for the debugging of
JDOM, but much less so for debugging of user programs that use JDOM. The latter
case should be much more common, and I think that an easier to read (i.e. XML)
output is better.

Alex Rosen
SilverStream Software

More information about the jdom-interest mailing list