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

Retrieving a Java HashMap into a perl hash

Expand Messages
  • loundry2000
    Hello All, With Duncan s suggestion I was able to send a hash from SOAP::Lite and turn it into a Java HashMap. I am now trying to go the other way. Here is
    Message 1 of 2 , Apr 1 10:44 AM
    View Source
    • 0 Attachment
      Hello All,

      With Duncan's suggestion I was able to send a hash from SOAP::Lite and
      turn it into a Java HashMap. I am now trying to go the other way.
      Here is the response I get back from the server:

      <?xml version="1.0" encoding="UTF-8"?>
      <SOAP-ENV:Envelope
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <SOAP-ENV:Body>
      <ns1:setHashtableResponse
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:ns1="MyService">
      <setHashtableResult href="#id0"/>
      </ns1:setHashtableResponse>
      <multiRef id="id0" SOAP-ENC:root="0"
      xsi:type="ns2:HashMap"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:ns2="urn:MyService">
      <item>
      <key xsi:type="xsd:string">profession</key>
      <value xsi:type="xsd:string">political genius</value>
      </item>
      <item>
      <key xsi:type="xsd:string">lname</key>
      <value xsi:type="xsd:string">Browne</value>
      </item>
      <item>
      <key xsi:type="xsd:string">fname</key>
      <value xsi:type="xsd:string">Harry</value>
      </item>
      </multiRef>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>

      How can I (using SOAP::Lite) turn the xml above into the following
      hash:

      %hash = (
      fname => 'Harry',
      lname => 'Browne',
      profession => 'political genius'
      );

      ?

      Thanks,
      Jimmy
    • Paul Kulchenko
      Hi, Jimmy! ... I don t know why they use HashMap instead of Map type they invented. Anyway, to do that you need to do two things: 1. create package that will
      Message 2 of 2 , Apr 1 11:09 AM
      View Source
      • 0 Attachment
        Hi, Jimmy!

        > xsi:type="ns2:HashMap"
        I don't know why they use HashMap instead of Map type they invented.

        Anyway, to do that you need to do two things:

        1. create package that will handle types in specified schema (we just
        refer to as_map method):

        BEGIN {
        package MyService::Deserializer;
        sub as_HashMap;
        *as_HashMap = \&SOAP::XMLSchemaApacheSOAP::Deserializer::as_map;
        }

        2. register it in deserializer:

        $d = SOAP::Deserializer->new;
        $d->xmlschemas->{'urn:MyService'} = 'MyService::Deserializer';
        -------------------------------------^^^^^^^^^^^^^^^^^^^^^^^ class
        ------------------^^^^^^^^^^^^^ namespace

        Hope it helps.

        Best wishes, Paul.

        --- loundry2000 <loundry2000@...> wrote:
        > Hello All,
        >
        > With Duncan's suggestion I was able to send a hash from SOAP::Lite
        > and
        > turn it into a Java HashMap. I am now trying to go the other way.
        > Here is the response I get back from the server:
        >
        > <?xml version="1.0" encoding="UTF-8"?>
        > <SOAP-ENV:Envelope
        > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        > <SOAP-ENV:Body>
        > <ns1:setHashtableResponse
        >
        > SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        > xmlns:ns1="MyService">
        > <setHashtableResult href="#id0"/>
        > </ns1:setHashtableResponse>
        > <multiRef id="id0" SOAP-ENC:root="0"
        > xsi:type="ns2:HashMap"
        > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        > xmlns:ns2="urn:MyService">
        > <item>
        > <key xsi:type="xsd:string">profession</key>
        > <value xsi:type="xsd:string">political genius</value>
        > </item>
        > <item>
        > <key xsi:type="xsd:string">lname</key>
        > <value xsi:type="xsd:string">Browne</value>
        > </item>
        > <item>
        > <key xsi:type="xsd:string">fname</key>
        > <value xsi:type="xsd:string">Harry</value>
        > </item>
        > </multiRef>
        > </SOAP-ENV:Body>
        > </SOAP-ENV:Envelope>
        >
        > How can I (using SOAP::Lite) turn the xml above into the following
        > hash:
        >
        > %hash = (
        > fname => 'Harry',
        > lname => 'Browne',
        > profession => 'political genius'
        > );
        >
        > ?
        >
        > Thanks,
        > Jimmy
        >
        >
        > ------------------------ 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!?
        Yahoo! Greetings - send holiday greetings for Easter, Passover
        http://greetings.yahoo.com/
      Your message has been successfully submitted and would be delivered to recipients shortly.