CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Replace CDATA

 



0815
Novice

Jun 22, 2009, 12:03 PM

Post #1 of 3 (2045 views)
Replace CDATA Can't Post

Hello,

i have the next problem. I will replace this CDATA:


Quote
<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:

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)


1arryb
User

Jun 22, 2009, 2:07 PM

Post #2 of 3 (2015 views)
Re: [0815] Replace CDATA [In reply to] Can't Post

Hi 0815,

1. You have a typo in your solmankey() subroutine. Change:

Code
my $strval = $ele->first_child('strval');

to:

Code
my $strval = $fld->first_child('strval');


2. Call $ncdata->flush() at the end of solmankey().

3. Get rid of extraneous print statements.

Cheers,

Larry


(This post was edited by 1arryb on Jun 22, 2009, 2:09 PM)


0815
Novice

Jun 22, 2009, 2:22 PM

Post #3 of 3 (2010 views)
Re: [1arryb] Replace CDATA [In reply to] Can't Post

Hi Larry,

ich found my bug in the same time.

Thanks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives