Reputation: 39
I have an XML file that contains several lines like this:
<Teste Time="380643" TT="380592" Win="-2" Xl="28" Yl="55" />
<Teste Time="380660" TT="380592" Win="-2" Xl="28" Yl="55" />
I need to add a fixed number to every instance of the Time
attribute, e.g. 380643 + 10000
, and get an XML file with the new lines, e.g. <Time="390643" TT="380592" Win="-2" Xl="28" Yl="55"/>
. Is this possible using Perl? If so, how? If not, what should I do?
Upvotes: 1
Views: 64
Reputation: 27525
Use XML::Twig with twig_roots
:
my $twig=XML::Twig->new(
twig_roots =>
{ Time => sub { $_->set_att( TT => $_->att('TT')+10000 )->flush; }
},
twig_print_outside_roots => 1
);
$twig->parsefile('myXmlFile.xml');
Upvotes: 1