# XML::Rules bug?? # Just want to change some attributes on some tags # Repeated tags, some nested within other handled tags #!/usr/bin/perl use strict; use warnings; use XML::Rules; my @rules = ( B => sub { my $attr = $_[1]; $attr->{FOO} = "HELLO"; return $_[0] => $attr; }, C => sub { my ( $tag, $attr, $context ) = @_; $attr->{BAR} = "GOOD" if exists($attr->{BAR}); $attr->{DEF} = "BOO" if exists($attr->{DEF}); # THIS puts "@" at the front of the unnested tag $tag = '@'.$tag; # THIS works, but is more of a hassle #$tag = '@'.$tag if $context->[-1] eq 'Z'; return $tag => $attr; }, ); my $p = XML::Rules->new( rules => \@rules, style => 'filter', ); my $xml = < EOT $p->filter($xml, \*STDOUT);