in reply to Re^2: {KOHA}Parse XML and assign to variables.
in thread {KOHA}Parse XML and assign to variables.

So, does it still work if you add XML::Simple in, without adding in LWP::UserAgent?

  • Comment on Re^3: {KOHA}Parse XML and assign to variables.

Replies are listed 'Best First'.
Re^4: {KOHA}Parse XML and assign to variables.
by scolife (Novice) on Sep 15, 2015 at 12:09 UTC
    Yeah It works
    #!/usr/bin/perl #script to do a borrower enquiry/bring up borrower details etc #written 20/12/99 by chris@katipo.co.nz # Copyright 2000-2002 Katipo Communications # Copyright 2013 BibLibre # # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Koha is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Koha; if not, see <http://www.gnu.org/licenses>. use CGI; use C4::Auth; use C4::Output; use C4::Items; use C4::Context; use LWP::Simple; #use XML::Simple; use XML::Parser; use Data::Dumper; use C4::Members; #use LWP::UserAgent; use C4::Branch qw(GetBranches); use utf8; my $input = new CGI; my $remoteip= $input->remote_host(); my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "members/addfromsisi.tt" +, query => $input, type => "intranet", authnotrequired => 0, flagsrequired => {borrowers => 1}, }); my $rfid= $input->param('rfid'); my $op= $input->param('op'); # request my $ua = LWP::UserAgent->new; my $response = $ua->get("https://***************/studentservic +e/service.asmx/give_to_koha_byStudentCard?cardNR=$rfid&ip=$remoteip") +; my $xml=$response->content; my $xs = new XML::Simple(keeproot =>0,searchpath => ".",forcea +rray => 1,); my $ref = $xs->XMLin($xml); my $firstname=${$ref->{firstname}}[0]; my $lastname=${$ref->{lastname}}[0]; my $sisiid=${$ref->{sisiid}}[0]; my $school=${$ref->{school}}[0]; my $program=${$ref->{program}}[0]; my $registerNr=${$ref->{registerNr}}[0]; my $userStatus=${$ref->{userStatus}}[0]; my $usertype=${$ref->{usertype}}[0]; my $photo=${$ref->{photo}}[0]; my $branch=${$ref->{abbrevm}}[0]; my $op= $input->param('op'); # save when op= "save" my %newdata; if($op eq "save"){ %newdata =("cardnumber"=>"$rfid", "surname"=>"$lastname", "firstname"=>"$firstname", "initials"=>"$registerNr", "address"=>"$program", "userid"=>"$sisiid", "categorycode"=>'ST', "branchcode"=>'EZS', "password"=>'aaaaaaa' ); my $borrowernumber=&AddMember(%newdata); #PutPatronImage('aaaaaaaaa', 'image/jpeg', $imgfile); if (defined $borrowernumber) { my $q = new CGI; print $q->redirect(-uri=>"moremember.pl?borrowernumber +=$borrowernumber"); } }# save end $template->param( rfid=>$rfid, photo=>$photo, firstname=>$firstname, lastname=>$lastname, sisiid=>$sisiid, school=>$branch, program=>$program, registerNr=>$registerNr, userStatus=>$userStatus, usertype=>$usertype, remoteip=>$remoteip, op=>$op, res=> $imgfile, ); output_html_with_http_headers $input, $cookie, $template->output;

      I'm trying to work with you to reduce your program to a very minimal example that exhibits the error but does not rely on modules that are maybe not installed.

      The program you show needs LWP::UserAgent, CGI, XML::Parser (not XML::Simple!) and various C4 modules. Please work on removing as many modules as possible from that list. Also, consider replacing the AddMember function by something that just outputs the values so that we can easily check if the error happens before or after writing to the database.

        I am using template toolkit. So I can pass values to template. And It shows normal

        When I call AddMember function

        It inserts hash(HASH(0x5777c30) .. etc) I removed some module usage from code so
        #!/usr/bin/perl use CGI; use C4::Auth; use C4::Output; use C4::Context; use XML::Simple; use C4::Members; use LWP::UserAgent; use utf8; my $input = new CGI; my $remoteip= $input->remote_host(); my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "members/addfromsisi.tt" +, query => $input, type => "intranet", authnotrequired => 0, flagsrequired => {borrowers => 1}, }); my $rfid= $input->param('rfid'); my $op= $input->param('op'); # request my $ua = LWP::UserAgent->new; my $response = $ua->get("https:/************/studentservice/se +rvice.asmx/give_to_koha_byStudentCard?cardNR=$rfid&ip=$remoteip"); my $xml=$response->content; # parse my $xs = new XML::Simple(keeproot =>0,searchpath => ".",forcea +rray => 1,); my $ref = $xs->XMLin($xml); my $firstname=${$ref->{firstname}}[0]; my $lastname=${$ref->{lastname}}[0]; my $sisiid=${$ref->{sisiid}}[0]; my $school=${$ref->{school}}[0]; my $program=${$ref->{program}}[0]; my $registerNr=${$ref->{registerNr}}[0]; my $userStatus=${$ref->{userStatus}}[0]; my $usertype=${$ref->{usertype}}[0]; my $photo=${$ref->{photo}}[0]; my $branch=${$ref->{abbrevm}}[0]; my $op= $input->param('op'); # save when op= "save" my %newdata; if($op eq "save"){ %newdata =("cardnumber"=>"$rfid", "surname"=>"$lastname", "firstname"=>"$firstname", "initials"=>"$registerNr", "address"=>"$program", "userid"=>"$sisiid", "categorycode"=>'ST', "branchcode"=>'EZS', "password"=>'aaaaaaa' ); my $borrowernumber=&AddMember(%newdata); if (defined $borrowernumber) { my $q = new CGI; print $q->redirect(-uri=>"moremember.pl?borrowernumber +=$borrowernumber"); } }# save end $template->param( rfid=>$rfid, photo=>$photo, firstname=>$firstname, lastname=>$lastname, sisiid=>$sisiid, school=>$branch, program=>$program, registerNr=>$registerNr, userStatus=>$userStatus, usertype=>$usertype, remoteip=>$remoteip, op=>$op, res=> $imgfile, ); output_html_with_http_headers $input, $cookie, $template->output;