|
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. ;-)
|