Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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.


Comment on Re: XML::Twig removing tags from content
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928041]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2015-07-05 22:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls