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

I have a soap client that I have implemented (thanks for all your help on that one) and now I have to decipher the data that comes back. I think I have all the componenets, I just can't read the XML that is returned. The code is as follows:
my $s = SOAP::Lite -> uri ('This is my URI') -> proxy ('This is my proxy.asmx') -> on_action(sub{join '/', @_}) -> on_fault(sub{}); $result = $s->PerformUpdate($data)->result; if ($result) { my $xs = new XML::Simple(keeproot => 1); my $XMLref = $xs->XMLin($result, suppressempty => ''); print $XMLref->{wellmed}->{wellmed.ack}->{errors}; } #using data dumper I get the following output $VAR1 = { 'wellmed' => { 'wellmedack' => {}, 'wellmed.ack' => { 'error +s' => '0', 'wellmed.response' => 'User data updated for ID: aac20fd41 +e07ea11d9bfc1ac192a16aa77', 'responses' => '1' } } };
I can not figure out how to get the bottom nodes out of this XML structure. On a complete side note, I have the on_fault() doing nothing. Is there a variable I can use to capture a fault that is returned - such as on_fault(sub {print "the fault"}). Thanks for all your help.

Replies are listed 'Best First'.
Re: Decipher HASH from XML
by tachyon (Chancellor) on Sep 24, 2004 at 00:48 UTC

    Your issue is that Perl does not like hash keys in the form 'foo.bar' - if you don't quote the 'foo.bar' it is FUBAR.

    $hash = { 'foo.bar' => 'foo.bar_v', 'foobar' => 'foobar_v' }; print $hash->{foo.bar}; __DATA__ foobar_v <-- note we have lost the . in the key so get the wrong val +ue

    You get at the data as shown by quoting the 'str.str' keys so as to avoid the issue.

    $VAR1 = { 'wellmed' => { 'wellmedack' => {}, 'wellmed.ack' => { 'errors' => '0', 'wellmed.response' => 'User da +ta updated for ID: aac20fd41e07ea11d9bfc1ac192a16aa77', 'responses' => '1' } } }; print "Response: ", $VAR1->{'wellmed'}->{'wellmed.ack'}->{'wellmed.res +ponse'}, "\nErrors: ", $VAR1->{'wellmed'}->{'wellmed.ack'}->{'errors'},

    cheers

    tachyon

      Thank you again, I made the change to replace the "." with another character and everything worked like a charm.
Re: Decipher HASH from XML
by JediWizard (Deacon) on Sep 23, 2004 at 21:35 UTC

    SOAP::Lite will decipher the xml for you. If the service you are connecting to, is returning a HASH, SOAP::Lite will interpret the XML used for the communication protocol back into a hash, and $result will be a hashref. Is the SOAP Service you are connecting to returning XML encoded into the XML SOAP uses for communication?

    May the Force be with you