Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: XML::Twig removing tags from content

by mirod (Canon)
on Sep 27, 2011 at 07:49 UTC ( #928041=note: print w/replies, xml ) Need Help??

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 (Scribe) on Sep 28, 2011 at 18:15 UTC
    Thanks -- yeah I noticed that 'parent' and 'ancestor' seem to be the same thing -- thanks for clarifying how to eliminate the false positives. Scott

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928041]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-06-23 07:00 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.