Question

Let us assume that my XML file is like:

<? xml version="1.0" encoding="iso-8859-1" ?>
  <Body>
    <RequiredTag>
      #VALUE#
    </RequiredTag>
  </Body>

How can I change the value of the required tag using Perl?

E.g.:

$XmlHandle->{XML}->{Body}->{RequiredTag} = "RequiredValue";
Was it helpful?

Solution

With XML::Twig::

#!/usr/bin/perl

use strict;
use warnings;

use XML::Twig;

XML::Twig->new( twig_handlers => 
                  { RequiredTag => sub { $_->set_text( 'RequiredValue') } },
                pretty_print => 'indented',
              )
         ->parsefile( 'my_file.xml')
         ->print;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top