Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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]
[marto]: hmm, the site running really slow for anyone else?
[choroba]: In recent days, I connect to directly, otherwise I'm getting timeouts
[choroba]: YMMV

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2018-01-16 10:46 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (177 votes). Check out past polls.