I have a XML file, and I want to read it - remove a node - save it. I run perl from terminal (perl script.pl)
example XML (filename.xml):
<?xml version="1.0" encoding="UTF-8"?>
<twice>
<inner>
<twice>
<name>John</name>
<surname>Smith</surname>
</twice>
<twice>
<name>Alan</name>
<surname>Bowler</surname>
</twice>
<twice>
<name>Michael</name>
<surname>Deck</surname>
</twice>
</inner>
</twice>
example perl script (script.pl):
use strict;
use warnings;
use XML::LibXML;
my $filename = "filename.xml";
my $parser = XML::LibXML->new();
my $xmldoc = $parser->parse_file($filename);
for my $dead ($xmldoc->findnodes(q{/twice/inner/twice[surname = "Bowler"]})) {
$dead->unbindNode;
}
print $xmldoc->toString;
Now it outputs the expected result in terminal, but without saving the file.
Expected result (filename.xml):
<?xml version="1.0" encoding="UTF-8"?>
<twice>
<inner>
<twice>
<name>John</name>
<surname>Smith</surname>
</twice>
<twice>
<name>Michael</name>
<surname>Deck</surname>
</twice>
</inner>
</twice>
I have searched for many hours and couldn't find anything, sorry if it's a duplicate!
This is my first experience with perl so please any help would be welcomed, thanks.