
0815
Novice
Jun 22, 2009, 12:03 PM
Post #1 of 3
(3888 views)
|
Hello, i have the next problem. I will replace this CDATA:
<row> <fld name="solManKey"> <strval><![CDATA[]]> </strval> </fld> </row> I find the field but my replace do not work. Can anybody help me? My code: use FindBin (); use lib "$FindBin::Bin"; use strict; use warnings; use XML::Twig; use Term::ANSIColor qw(:constants); open FILE, '>', "inifile_out" or die "failed to open inifile_out"; my $handlers = { 'row' => \&solmankey }; my $twig = new XML::Twig( twig_handlers => $handlers ); my $inifile_in="inifile_CIINST"; $twig->parsefile($inifile_in); $twig->set_pretty_print("indented"); $twig->flush( \*FILE ); close FILE; ############################################################################### # replace all variables from inifile and create inifile_template sub solmankey { my ( $twig, $ele ) = @_; my $fld= $ele->first_child('fld'); return unless $fld; my $name =""; my $value =""; my $att_name =""; my $att_value =""; while( ( $name, $value) = each( %$fld )) { #print "\t\t$name #### => $value\n"; if ($name eq "att"){ while (( $att_name, $att_value) = each (%$value)){ if ($att_value eq "solManKey"){ print "\t\t $att_name ===> $att_value \n"; my $strval = $ele->first_child('strval'); return unless $strval; my $cdata = $strval->first_child('#CDATA'); return unless $cdata; $cdata->text; print "#######".$cdata; my $ncdata = new XML::Twig::Elt( '#CDATA', "xxxxxx" ); $ncdata->replace($cdata); } } } } }
(This post was edited by 0815 on Jun 22, 2009, 12:25 PM)
|