paisani has asked for the wisdom of the Perl Monks concerning the following question:
Gives me this output -use strict; use warnings; use XML::Twig; my $xml = q( <sites> <site siteid="ONE"> <name>name1</name> <address>address1</address> <contact>contact1</contact> </site> <site siteid="TWO"> <name>name2</name> <address>address2</address> <contact>contact2</contact> </site> </sites> ); my %handlers = ( 'name[string() =~ /name2/]' => sub { my ($twig, $cnt) + = @_; $cnt->parent->delete;} ); my $twig= new XML::Twig( PrettyPrint => 'indented', twig_handlers => + \%handlers); $twig->parse($xml); print $twig->sprint;
What am I missing?? I wanted to delete the entire section for siteid=TWO.<sites> <site siteid="ONE"> <name>name1</name> <address>address1</address> <contact>contact1</contact> </site> <address>address2</address> <contact>contact2</contact> </sites>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Twig delete not deleting the entire section?
by choroba (Cardinal) on Mar 14, 2018 at 16:46 UTC | |
by paisani (Acolyte) on Mar 14, 2018 at 17:33 UTC | |
by poj (Abbot) on Mar 14, 2018 at 19:02 UTC | |
|
Re: Twig delete not deleting the entire section?
by Discipulus (Canon) on Mar 14, 2018 at 19:56 UTC | |
|
Re: Twig delete not deleting the entire section?
by Anonymous Monk on Mar 15, 2018 at 12:25 UTC | |
|
Re: Twig delete not deleting the entire section?
by paisani (Acolyte) on Mar 14, 2018 at 20:35 UTC | |
by Anonymous Monk on Mar 16, 2018 at 22:37 UTC |