[jdom-interest] Merging text nodes

Jason Hunter jhunter at acm.org
Tue Feb 19 10:29:13 PST 2002


> On Tue, 19 Feb 2002, Dennis Sosnoski wrote:
> 
> > I agree with Alex that the auto-magical text merging behavior can create
> > problems. Why not use a normalize()-type method to handle this (which
> > could even be in a support class, rather than in the core classes)? That
> > way the code complexity is reduced and there's no overhead for checking
> > possible merges unless the user actually makes the request.
> 
> I agree whole-heartedly with this recommendation.

I do also.

> If anything is done dynamically, on-the-fly, then programatically
> constructed documents may undergo an 'optimization' run after
> each modification.  I think it's best to externalize this functionality,
> and let the developer decide when/if this should be done.
> 
> Possibly, add a switch to the FooBuilders (or make it default) to
> use the normalization after the document is built.

We do normalize during SAXBuilder build time.  That's because SAX's
characters() callback may be called dozens of times for a single text
block depending on the parser, so we use string buffers to piece them
together before creating a Text object.  For DOMBuilder we do a direct
mapping to what was in DOM.

-jh-



More information about the jdom-interest mailing list