Abhijit10089 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have to port an application from Unix to Linux box and I am facing issue in one of the web service call the application is making: I am performing a web service call using SOAP::Lite (1.10) and below the XML response received (printing it using Data Dumper):
$VAR1 = bless( { '_content' => [ 'SOAP:Envelope', { 'xmlns:SOAP' => 'http://schemas.xml +soap.org/soap/envelope/' }, [ [ 'SOAP:Header', {}, '', undef, '', '{http://schemas.xmlsoap.org/soap +/envelope/}Header', {} ], [ 'SOAP:Body', {}, [ [ 'ns0:MT_LABEL_IN', { 'xmlns:ns0' => 'http://emdc +hemicals.com/xi/label/masterdata' }, [ [ 'HEADER', {}, [ [ 'material', {}, '12659-250GM', undef, '12659-250GM', 'material', {} ], [ 'batch', {}, 'D00166202', undef, 'D00166202', 'batch', {} ], [ 'material_desc', {}, 'Albumin, Bovine Seru +m, Fract 1PC x 250GM', undef, 'Albumin, Bovine Seru +m, Fract 1PC x 250GM', 'material_desc', {} ], [ 'plant', {}, 'US05', undef, 'US05', 'plant', {} ] ], undef, { 'batch' => 'D00166202', 'plant' => 'US05', 'material_desc' => 'Alb +umin, Bovine Serum, Fract 1PC x 250GM', 'material' => '12659-25 +0GM' }, 'HEADER', {} ] ], undef, { 'HEADER' => $VAR1->{'_conte +nt'}[2][1][2][0][2][0][4] }, '{http://emdchemicals.com/xi/ +label/masterdata}MT_LABEL_IN', {} ] ], undef, { 'MT_LABEL_IN' => $VAR1->{'_cont +ent'}[2][1][2][0][4] }, '{http://schemas.xmlsoap.org/soap +/envelope/}Body', {} ] ], undef, { 'Body' => $VAR1->{'_content'}[2][1] +[4], 'Header' => '' }, '{http://schemas.xmlsoap.org/soap/env +elope/}Envelope', {} ], '_context' => undef, '_current' => [ $VAR1->{'_content'} ] }, 'SOAP::SOM' );
Now when i am trying to access the values in the Header Tag: print Dumper ($a->{_value}); where $a is $xmlResponse->dataof("//MT_LABEL_IN/*")
$VAR1 = [ \bless( { '_signature' => [], '_value' => [ bless( { '_name' => 'material', '_signature' => [], '_value' => [ '12659-250GM +' ], '_prefix' => '', '_attr' => {} }, 'SOAP::Data' ), bless( { '_name' => 'batch', '_signature' => [], '_value' => [ 'D00166202' ], '_prefix' => '', '_attr' => {} }, 'SOAP::Data' ), bless( { '_name' => 'material_desc' +, '_signature' => [], '_value' => [ 'Albumin, Bo +vine Serum, Fract 1PC x 250GM' ], '_prefix' => '', '_attr' => {} }, 'SOAP::Data' ), bless( { '_name' => 'plant', '_signature' => [], '_value' => [ 'US05' ], '_prefix' => '', '_attr' => {} }, 'SOAP::Data' ) ], '_attr' => {} }, 'SOAP::Data' ), {} ];
The issue is that I am not able to pull the values of tag's' like plant, material_desc etc.

Could someone please let me know how to perform this?

Best Regards,
Abhijit Singh Dahiya

Replies are listed 'Best First'.
Re: SOAP::Lite Response Parsing
by Anonymous Monk on Aug 22, 2014 at 08:54 UTC

    :) That response looks parsed already :) See Re: Parsing SOAP::Lite results (with Data::Diver)

    The issue is that I am not able to pull the values of tag's' like plant, material_desc etc.

    Maybe you want "//MT_LABEL_IN/HEADER/*" ? IE keep doing what you're already doing?

    Works for me

    for my $d ( $xmlResponse->dataof("//MT_LABEL_IN/HEADER/*") ){ print "$d ", $d->name, " = ", $d->value, "\n", } __END__ SOAP::Data=HASH(0xa6a76c) material = 12659-250GM SOAP::Data=HASH(0xa6ab5c) batch = D00166202 SOAP::Data=HASH(0xa6af74) material_desc = Albumin, Bovine Serum, Fra +ct 1PC x 250GM SOAP::Data=HASH(0xa6b744) plant = US05

    or post code that shows that, code that runs, not fragments, maybe code like Re^3: SOAP::Lite - Attribute in array

    or the acdtual xml of the response, as the DDumper you've shown doesn't have Purity(1)

    This invocation of DDumper has purity

    sub ppp { use Data::Dumper(); return Data::Dumper->new( [@_] )->Sortkeys( 1 )->Purity( 1 )->Inde +nt( 0 ) ->Useqq( 1 )->Dump . '$VAR1;'; } ## end sub ppp

    Links to soap tips including getting tidy debugging info in Re: Why can't SOAP::Lite deserialize its own output? (it does)

      Sorry for the Late reply, but yes it did worked. Not sure why my code was not working though. Thanks a ton. Best Regards, Abhijit Singh Dahiya