in reply to Changing XML Tag value in Perl Script

I can't tell what GetXMLValue does, but generally using a module such as XML::Twig is the smart way to handle XML parsing and manipulation problems. Consider:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $t = XML::Twig->new( twig_roots => {'CLIENT_INFO/FIELD' => \&convert}, twig_print_outside_roots => 1 ); $t->parse(*DATA); sub convert { my ($t, $elt) = @_; my $txt = $elt->text(); $elt->set_text('FINANCIAL SYSTEMS') if $txt =~ /FINANCE GROUP/i; $elt->print (); } __DATA__ <CLIENT_INFO> <LOCATION> New York </LOCATION> <FIELD> FINANCE GROUP </ +FIELD> <NO_OF_WORKERS> 123 </NO_OF_WORKERS> </CLIENT_INFO>

Prints:

<CLIENT_INFO> <LOCATION> New York </LOCATION> <FIELD>FINANCIAL SYSTEMS +</FIELD> <NO_OF_WORKERS> 123 </NO_OF_WORKERS> </CLIENT_INFO>
True laziness is hard work

Replies are listed 'Best First'.
Re^2: Changing XML Tag value in Perl Script
by Rajpreet1985 (Initiate) on Apr 13, 2011 at 20:44 UTC
    Thanks for your inputs. However problem in my case is my production environment has just XML::Parser . I am not allowed to download XML::Twig or any other module. So options are either to directly manipulate or use XML::Parser. I have not done XML parsing anytime earlier . Would appreciate your inputs. Thanks.

      Well, you could spend the time to recreate the parts of XML::Twig that you need for this project, or you could convince "management" that there is a significant gain to be made by making an exception to the "can't use external modules" rule in this case, or see Yes, even you can use CPAN.

      True laziness is hard work