#!/usr/bin/perl use strict; use warnings; use autodie qw(open); use Test::More; use XML::Twig; my( $in, $expected)= do { local $/="\n\n"; ; }; is( remove_policy_rule( $in), $expected, 'simplest code'); is( with_flush( $in), $expected, 'with flush'); done_testing(); sub remove_policy_rule { my( $in)= @_; my $t= XML::Twig->new( twig_handlers => { policyrules => sub { $_->erase; } }, pretty_print => 'indented', ) ->parse( $in); return $t->sprint; } sub with_flush { my( $in)= @_; my $out; open( my $fh, '>', \$out); my $t= XML::Twig->new( twig_handlers => { policyrules => sub { $_->erase; $_[0]->flush( $fh); } }, pretty_print => 'indented', ) ->parse( $in); return $out; } __DATA__