XML-Twig - Re: Coalescing adjacent #PCDATA elements?

Posted on Sun Jul 1 22:44:41 2007 by jeunice in response to 5592 (See the whole thread of 4)
Re: Coalescing adjacent #PCDATA elements?
mirod is, as usual, way ahead of me! normalize() does the trick.

Unfortunately, even in the 3.30 development version, normalize() must be explicitly called. I can see a need for that in some situations, but at least in my document processing work, I generally want normalized trees. So rather than calling normalize() whenever I am unsure whether the tree has become un-normalized, I think I'll wrap the few editing methods that lead to un-normalized trees (cut and erase/unwrap, primarily) with a
my $parent = $elt->parent; $elt->cut; # or unwrap, or erase $parent->normalize();

treatment. I might even override XML::Twig::Elt methods with such a front-end to do this auto-magically. That would seem to deterministically keep the tree normalized. Does that seem reasonable? Any other edit methods I should similarly worry about?

Finally, mirod, feel free to add an auto-normalization option. ;-)
Direct Responses: 5628 | Write a response