Question

My code below is connecting to a .asmx web service to get data.

The code extractes the CDATA into %keyHash below.

Rather than parsing the entire CDATA, is it possible to grab a specific data element in the SOAP CDATA by calling out it's path?

I read that I could use $soap->valueof() to get the data, is that correct? and that this would require use of XPATH?

I ask as I am unfamiliar with this and I do not know if I am on the right path, are there other ways to do this?

My $soap->valueof('//Images/Front') attempts have failed, saying that, my first time using XPATH, could be getting it wrong but at this point I am guessing if this is the right way to go.

Any direction on whether I am on the right or wrong path in using valueof() would be appreciated!

Here is the code, it works. I have also included the obscurated CDATA data extracted from %keyHash.

use SOAP::Lite +trace => 'all';

 $soap = SOAP::Lite
    -> uri('..../')
    -> on_action( sub { join '/', '.....', $_[1] } )
    -> proxy('......asmx');

 $method = SOAP::Data->name('methodName')
    ->attr({xmlns => ...../'});


 @params = (
            SOAP::Data->name(tran=> 765) ->type(''),
            SOAP::Data->name(token => 0)->type(''),
            SOAP::Data->name(type=> 1)->type('')
             );



%keyHash = %{ $soap->call($method => @params)->body->{'GetmethodNameResponse'}->{'GetmethodNameResult'} };

# iterate through all fields and print them
foreach my $k (keys %keyHash) {
        print "$k=$keyHash{$k}\n";
}

Example of the data output, I want the data in the string "THIS_IS_THE_DATA_I_WANT" (unable to put the path here for some reason)

RequestResult=0
Xml=<?xml version="1.0" encoding="utf-8"?>
<Images>
    <Front>THIS_IS_THE_DATA_I_WANT</Front>
</Images>

Thank You,

A

Was it helpful?

Solution

I solved this by using the following, hope it helps someone...

use XML::Simple; 
%keyhash = %{ $soap->call($method => @params)->body->{'GetCheckXmlResponse'}->{'GetCheckXmlResult'}};
$getxml= %keyhash->{Xml}; 
$parsexml = XMLin($getxml); 
print Dumper($parsexml); # Use this to point to your data and then grab it as per the line below 
$frontside = $parsexml->{Images}->{Front}; 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top