in reply to Re: Twig delete not deleting the entire section?
in thread Twig delete not deleting the entire section?
Gave the following 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) = @_; my $parent = $cnt->parent; foreach ($parent->children) { print "Deleting: " . $_->text . "\n"; $_->delete; } $parent->delete; } ); my $twig= new XML::Twig( PrettyPrint => 'indented', twig_handlers => + \%handlers); $twig->parse($xml); print $twig->sprint;
Deleting: name2 <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^3: Twig delete not deleting the entire section?
by poj (Abbot) on Mar 14, 2018 at 19:02 UTC |