[jdom-interest] Preserving whitespace

Jason Hunter jhunter at collab.net
Wed Apr 4 21:56:40 PDT 2001

"Rosen, Alex" wrote:
> I made a couple of changes to preserve the whitespace in an XML 
> document, so that it can be round-tripped better. Here's an 
> illustration of the problem. 
> ...
> There are three problems: (1) In the validating case, all whitespace is lost.

Yeah, because it was ignorable whitespace.  For those who aren't
familiar, the existence of a DTD allows the parser to defer some
whitespace is not important, and thus the memory footprint can be safely
reduced by not keeping it around.

Now, maybe it would be better to keep the whitespace and have a
setIgnoringElementContentWhitespace() method on the builder to indicate
if it can be ignored.  That method name comes from the JAXP spec which
offered this feature.

I'd still want another method that was more aggressive on removing
whitespace, like setIgnoringAllWhitespace().

The benefits to this approach is that you get a similarly whitespaced
document both with and without validation.  The downside is that only
people in the know about the set method (like 10% of users I bet) will
save memory.


> (2) In the non-validating case, the space between the DOCTYPE declaration and
> the first element is lost, 

That's already been fixed I believe, probably after beta6.  Alex, you
should upgrade.  :-)


More information about the jdom-interest mailing list