in reply to Changing XML Tag values in Perl
Using XML::Rules:
use strict; use warnings; use XML::Rules; my $xml = <<XML; <?xml version='1.0'?> <root> <test> <name>file</name> <href>file.txt</href> </test> <test> <name>file1</name> <href>file1.txt</href> </test> <notest> <name>file1</name> <href>file1.txt</href> </notest> </root> XML my $parser = XML::Rules->new ( style => 'filter', rules => { _default => 'raw', href => sub { my ($tag, $attr, $context) = @_; $attr->{_content} =~ s/\.txt$/.xml/i if $context->[-1] eq +'test'; return $tag => $attr; } } ); $parser->filter($xml);
|
|---|