in reply to modifying xml file and saving them in the same file using Perl and XML:Twig
Ignore this...
I looked at the tests on CPAN (http://cpansearch.perl.org/src/MIROD/XML-Twig-3.49/t/test_3_26.t), and they use flush():
use warnings; use strict; use XML::Twig; my $twig = XML::Twig->new( pretty_print => 'indented', twig_handlers => { jdk => sub { $_->set_text('JDK 1.8.0_40')->flush(); }, }, ); $twig->parsefile_inplace( 'nightly.xml', '.bak' ); __END__ <jdk>JDK 1.8.0_40</jdk> <jdk>JDK 1.8.0_40</jdk>
I got it to create a backup (nightly.xml.bak) properly, and the original nightly.xml file was modified, but it duplicates the line for me. I am using an older version of XML::Twig, 3.37. I didn't see any open bug reports on this topic.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: modifying xml file and saving them in the same file using Perl and XML:Twig
by choroba (Cardinal) on Apr 22, 2015 at 15:33 UTC |