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>
|
|---|
| 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 | |
by GrandFather (Saint) on Apr 13, 2011 at 23:12 UTC |