92sai has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am using PERL and XML::Twig I have made some changes in the xml file( changing the values of the tags). But i cannot write it in the same xml file. If i use parsefile_inplace() the whole xml file got empty. Please find the code below..
use XML::Twig; my $twig= XML::Twig->new( pretty_print => 'indented', twig_handlers => { jdk => sub{ $_->set_text( 'JDK 1.8.0_40' ) }, }, ); $twig->parsefile_inplace( 'nightly.xml', 'bak.*' ); $twig->flush;
part of xml file
<jdk>JDK 1.7.0_40</jdk>
if i use flush command it gives the desired output on cmd... if i use parsefile_inplace command it is emptying the nightly.xml... if i just use parsefile the original file is intact without changing the value i want to change.. My requirement is to edit the value and save it in the same file Thanks in advance.

Replies are listed 'Best First'.
Re: modifying xml file and saving them in the same file using Perl and XML:Twig
by toolic (Bishop) on Apr 22, 2015 at 12:54 UTC
      Using XML::XSH2, a wrapper around XML::LibXML:
      open nightly.xml ; xinsert text 'JDK 1.8.0_40' replace //jdk/text() ; save :b ;
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ