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: How can i use xml-moduls for my problem?: Edit Log



0815
Novice

Apr 16, 2009, 3:19 AM


Views: 3528
How can i use xml-moduls for my problem?

Hello,

how can i use xml-moduls for my problem? I have a xml file with lot of variables, which a like to replace. My variable (like XML_SID) are only in CDATA.



This are my first test to read it:


Code
#!/usr/bin/perl 
use XML::Simple;
use Data::Dumper;

$xml = new XML::Simple;

@xmlkeys=();
@xmlvals=();

$data = $xml->XMLin('inifile.xml', KeepRoot => 1);
&listhash ( $data, 0,"" );
XMLout($data, KeepRoot => 1, OutputFile => 'xinifile.xml');
print Dumper($data);

print "#############################################\n";

$numkeys=$#xmlkeys;

print $#xmlkeys,"\n";
print $#xmlvals,"\n";



foreach $t (@xmlvals) {
print $t,"\n";
}

print "#############################################\n";

foreach $t (@xmlkeys) {
print $t,"\n";
}

print "HIER\n";

###############################################################################
sub listhash {
my %myhash = %{$_[0]};
my $mylevel = $_[1];
my $parentkey=$_[2];
my $mykey = '';
my $myval = '';
my $myderefval = '';

foreach $mykey( keys(%myhash) ) {
# print "$mylevel KEY $mykey\n";
# print "$parentkey KEY $mykey\n";
$myval= $myhash{$mykey};
$myderefval=\$myhash{$mykey};

if ($myderefval =~ "^SCALAR") {
push (@xmlkeys, $parentkey.'**'.$mykey);
$myval =~ s/\s+$//g;
push (@xmlvals, $myval );

#if ($myval =~ "^SAPXML_DBSCHEMA" ) {
# print "HIER\n";
# die;
# $myhash{$mykey} = 'JOW_DBSCHEMA';
# }
}

if ($myderefval =~ "^REF") {
if ($myval =~ "^HASH") {
&listhash ( $myval, $mylevel+1, $parentkey.'**'.$mykey );
}
}
}
# return $mystring;

}


TX for any help!


(This post was edited by 0815 on Apr 19, 2009, 7:14 AM)


Edit Log:
Post edited by 0815 (Novice) on Apr 16, 2009, 7:51 AM
Post edited by 0815 (Novice) on Apr 19, 2009, 7:14 AM


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

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