in reply to unable to pass data
customer.xml <?xml version="1.0"?> <customer> <first_name>Frank</first_name> <last_name>Sanbeans</last_name> <dob>3/10</dob> <email>frank@example.com</email> </customer>
nba.xml <?xml version="1.0"?> <stats><player><name>Houston, Allan</name><g>69</g><ppg>20.1</ppg><rpg +>3.4</rpg><apg>2.8</apg><blk>14</blk></player> <player><name>Sprewell, Latrell</name><g>69</g><ppg>19.2</ppg><rpg>4.5 +</rpg><apg>4.0</apg><blk>15</blk></player> <player><name>Ewing, Patrick</name><g>49</g><ppg>14.6</ppg><rpg>10.0</ +rpg><apg>1.0</apg><blk>68</blk></player> </stats>
twig_client_parse #!/usr/bin/perlsupplier.xml <?xml version="1.0"?> <supplier-data> <supplier> <name>Supplier 1</name> <address>Address 1</address> <tel-no>012345</tel-no> </supplier> </supplier-data>
twig_rcvr_serveruse strict; use warnings; use XML::Simple; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $server_endpoint = "http://localhost/cgi-bin/RnD/twig/twig_rcvr_ser +ver.cgi"; # set custom HTTP Request header fields my $xml; my $req = HTTP::Request->new(POST => $server_endpoint); $req->header('content-type' => 'text/xml'); # for descending order use # my @files = reverse(glob("*.xml")); my @files = (glob("*.xml")); print "@files\n"; my $test; foreach $test(@files){ #print "this element: $test \n "; open FILE, $test or die $!; while(<FILE>){ $xml .= $_; #print $xml; } } $req->content($xml); my $resp = $ua->request($req); if ($resp->is_success){ my $message = $resp->decoded_content; print "Received reply:\n $message\n"; } else { print "HTTP POST error code: ", $resp->code, "\n"; print "HTTP POST error message: ", $resp->message, "\n"; }
#!/usr/bin/perl use strict; use warnings; use CGI; use DBI; use XML::Twig; use CGI::Carp 'fatalsToBrowser'; my $cgi = CGI->new; print $cgi->header(-type => "text/xml", -charset => "utf-8"); my $xml = $cgi->param("POSTDATA"); print "the data $xml is received"; my $username = "abcxyz"; my $password = "xyzabc"; my $dsn = "dbi:mysql:twig:127.0.0.1"; my $dbh = DBI->connect($dsn,$username,$password) or die "Cannot connec +t to database: $DBI::errstr"; my $sql1 = 'INSERT INTO twig_test(name,ppg,rpg,apg,g,blk) VALUES(?,?,?,?,?,?)'; my $sth1 = $dbh->prepare($sql1); my $sql2 = 'INSERT INTO customer(first_name,last_name,dob,email) VALUES(?,?,?,?)'; my $sth2 = $dbh->prepare($sql2); my $sql3 = 'INSERT INTO supplier(name,address,tel_no) VALUES(?,?,?)'; my $sth3 = $dbh->prepare($sql3); #test if($dbh){ print "print successfully connected to the database"; } my $twig = new XML::Twig( twig_handlers => {player => \&player, customer => \&customer, supplier => \&supplier} ); $twig->parsefile($xml); #$twig->print; sub player {my ($twig,$player) = @_; my @f=(); $f[0] = $player->field('name'); $f[1] = $player->field('ppg'); $f[2] = $player->field('rpg'); $f[3] = $player->field('apg'); $f[4] = $player->field('g'); $f[5] = $player->field('blk'); print $f[0], "\n"; print $f[1], "\n"; print $f[2], "\n"; print $f[3], "\n"; print $f[4], "\n"; print $f[5], "\n"; #print "\n"; $sth1->execute(@f) or die $DBI::errstr; } sub customer {my ($twig,$customer) = @_; my @f=(); $f[0] = $player->field('first_name'); $f[1] = $player->field('last_name'); $f[2] = $player->field('dob'); $f[3] = $player->field('email'); print $f[0], "\n"; print $f[1], "\n"; print $f[2], "\n"; print $f[3], "\n"; #print "\n"; $sth2->execute(@f) or die $DBI::errstr; } sub supplier {my ($twig,$supplier) = @_; my @f=(); $f[0] = $player->field('name'); $f[1] = $player->field('address'); $f[2] = $player->field('tel-no'); print $f[0], "\n"; print $f[1], "\n"; print $f[2], "\n"; #print "\n"; $sth3->execute(@f) or die $DBI::errstr; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: unable to pass data
by poj (Abbot) on Jun 03, 2014 at 10:49 UTC |