Loading ...
Sorry, an error occurred while loading the content.

help with ->valueof

Expand Messages
  • kowalski
    Hi Paul, _Still_ trying to complete the operation you outlined in message 1086. I have this: acmeclient.pl ... 1 use SOAP::Lite; 2 3 (blah blah blah, define
    Message 1 of 2 , Dec 18, 2001
    • 0 Attachment
      Hi Paul,


      _Still_ trying to complete the operation you outlined in message 1086.

      I have this:

      acmeclient.pl
      -------------
      1 use SOAP::Lite;
      2
      3 (blah blah blah, define $acme_wsdl, $param1 and $param2)
      4
      5 $acme_server = new SOAP::Lite
      6 -> service($acme_wsdl)
      7 -> getBalance($param1,$param2);
      8 $som = $acme_server->call;
      9 if ($som->fault) {
      die "FAULT: " . $som->faultcode . $som->faultstring . "\n";
      }
      10 %resp_hash = %{$som->valueof('//GETBALANCERESP')};
      11 $resp_scalar = $som->result;
      12 print "Response hash: " , scalar(%resp_hash), "\n";
      13 print "Response scalar: $resp_scalar\n;"


      When I run this I get

      Response hash: 0
      Response scalar: <?xml version="1.0"?>
      <GETBALANCERESP><ACCOUNT>719353</ACCOUNT><TIMESTAMP>1218174913</TIME
      STAMP><CURRENT_BALANCE_AVAIL>245</CURRENT_BALANCE_AVAIL></GETBALANCE
      RESP>

      (The lines are force-wrapped, so I'm sure it's all one long string)

      The hash seems to be empty, but there obviously was a response. I have also tried ->paramsout and gotten nothing. If I change line 10 to make $resp_hash to a scalar, I get a hashref but the first key is a hashref, which makes me think it's a null.

      Is there some intermediate step I'm missing?

      I feel like I'm getting closer to finding out how to do this and once I get this down the rest will be easy.

      Thanks for any help you can provide. This WILL eventually get through my head.
    • Paul Kulchenko
      Hello, There is no hash to parse. You return your XML code as string , so you receive it again as string. If you want to do something with it, you need to
      Message 2 of 2 , Dec 18, 2001
      • 0 Attachment
        Hello,

        There is no hash to parse. You return your XML code "as string", so
        you receive it again as string. If you want to do something with it,
        you need to parse it first.

        For example:

        you do on server side:

        return '<GETBALANCERESP>blah</GETBALANCERESP>';

        on client side you get:

        $xml = ...->result;

        $xml has unparsed XML fragment
        '<GETBALANCERESP>blah</GETBALANCERESP>' "as string"

        You can parse it using XML::Parser or SOAP::Deserializer:

        my $parsed = SOAP::Deserializer->deserialize($xml);
        %resp_hash = %{$parsed->valueof('//GETBALANCERESP')};
        --OR--
        %resp_hash = %{$parsed->root}; # because you want to get all elements
        starting from root.

        As an alternative you can return XML as fragment from server side
        using 'xml' pseudotype:

        return SOAP::Data->type(xml =>
        <GETBALANCERESP>blah</GETBALANCERESP>);

        then your fragment with ->valueof() should work. Hope it helps.

        Best wishes, Paul.

        --- kowalski <kowalski@...> wrote:
        > Hi Paul,
        >
        >
        > _Still_ trying to complete the operation you outlined in message
        > 1086.
        >
        > I have this:
        >
        > acmeclient.pl
        > -------------
        > 1 use SOAP::Lite;
        > 2
        > 3 (blah blah blah, define $acme_wsdl, $param1 and $param2)
        > 4
        > 5 $acme_server = new SOAP::Lite
        > 6 -> service($acme_wsdl)
        > 7 -> getBalance($param1,$param2);
        > 8 $som = $acme_server->call;
        > 9 if ($som->fault) {
        > die "FAULT: " . $som->faultcode . $som->faultstring .
        > "\n";
        > }
        > 10 %resp_hash = %{$som->valueof('//GETBALANCERESP')};
        > 11 $resp_scalar = $som->result;
        > 12 print "Response hash: " , scalar(%resp_hash), "\n";
        > 13 print "Response scalar: $resp_scalar\n;"
        >
        >
        > When I run this I get
        >
        > Response hash: 0
        > Response scalar: <?xml version="1.0"?>
        >
        <GETBALANCERESP><ACCOUNT>719353</ACCOUNT><TIMESTAMP>1218174913</TIME
        >
        STAMP><CURRENT_BALANCE_AVAIL>245</CURRENT_BALANCE_AVAIL></GETBALANCE
        > RESP>
        >
        > (The lines are force-wrapped, so I'm sure it's all one long string)
        >
        > The hash seems to be empty, but there obviously was a response. I
        > have also tried ->paramsout and gotten nothing. If I change line 10
        > to make $resp_hash to a scalar, I get a hashref but the first key
        > is a hashref, which makes me think it's a null.
        >
        > Is there some intermediate step I'm missing?
        >
        > I feel like I'm getting closer to finding out how to do this and
        > once I get this down the rest will be easy.
        >
        > Thanks for any help you can provide. This WILL eventually get
        > through my head.
        >
        >
        >
        > ------------------------ Yahoo! Groups Sponsor
        >
        > To unsubscribe from this group, send an email to:
        > soaplite-unsubscribe@yahoogroups.com
        >
        >
        >
        > Your use of Yahoo! Groups is subject to
        > http://docs.yahoo.com/info/terms/
        >
        >


        __________________________________________________
        Do You Yahoo!?
        Check out Yahoo! Shopping and Yahoo! Auctions for all of
        your unique holiday gifts! Buy at http://shopping.yahoo.com
        or bid at http://auctions.yahoo.com
      Your message has been successfully submitted and would be delivered to recipients shortly.