in reply to XML::Twig removing tags from content
First, a few comments on your code: delete completely deletes the element, including its descendants. So you should do this after moving the children. Then you cannot paste an element that's already part of a tree. You need to cut it, then paste it. Or in short, to move it. move, like paste, needs a position and a referent as arguments: $c->move( before => $p) would work.
Also, I am not sure of the test on $p->parent('li'): it will try to find an li ancestor to $p, which may, possibly, find false positives (a p buried in a table within a li), so you probably want $p->parent->tag eq 'li', or $p->parent->is( 'li')).
That said, try $p->erase if( $p->parent->is( 'li')), that might just do what you want.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: XML::Twig removing tags from content
by slugger415 (Monk) on Sep 28, 2011 at 18:15 UTC |