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

Working with complex return datatypes

Expand Messages
  • Peter Mayr
    Hi, I just got into working with SOAP::Lite and find this module very helpful.. However I ran into a problem with complex datatypes and since I couldn t find
    Message 1 of 4 , Feb 17, 2005
      Hi,

      I just got into working with SOAP::Lite and find this module very helpful..

      However I ran into a problem with complex datatypes and since I couldn't
      find any pointers in the documentation and during a web search I'll try
      to ask for help here..

      I get the following return data from a web service...

      ----snip---

      <ANSWERS xsi:type="namesp2:ANSWERS"
      SOAP-ENC:arrayType="namesp2:AnswerElement[2]"><answer
      xsi:type="namesp2:AnswerElement" SOAP-ENC:arrayType="xsd:string[2]">
      <dc:source xsi:type="xsd:string">sourceA</dc:source>
      <dc:formatxsi:type="xsd:string">formatA</dc:format>
      </answer>

      <answer xsi:type="namesp2:AnswerElement"
      SOAP-ENC:arrayType="xsd:ur-type[5]">
      <dc:source xsi:type="xsd:string">sourceB</dc:source>
      <dc:format xsi:type="xsd:string">formatB</dc:format>
      </answer>
      </ANSWERS>
      ---/snip---

      If I use Data Dumper on the this
      e.g.: print Dumper($rc->{'ANSWERS'});

      I get the following

      --- snip ---
      Answers:$VAR1 = bless( [
      bless( [
      'sourceA',
      'formatA',
      ], 'AnswerElement' ),
      bless( [
      'sourceB',
      'formatB',
      ], 'AnswerElement' )
      ], 'ANSWERS' );
      --- /snip ---

      It seems that the labels 'dc:source' and 'dc:format' aren't accessible
      any more.. (which is a little bit inconvenient should the order change.. ;-)


      Is there a possibility to transform this type "AnswerElement" into a hash?

      I'm sorry if I have missed something glaringly obvious but I would
      appreciate any help

      Best Regards

      Peter Mayr
    • Duncan Cameron
      ... change. ... Hi Peter You seem to have a mismatch between defining the answer element as an array, SOAP-ENC:arrayType= xsd:string[2] , and wanting to see
      Message 2 of 4 , Feb 17, 2005
        At 2005-02-17, 16:26:20 Peter Mayr <mayr@...> wrote:

        >Hi,
        >
        >I just got into working with SOAP::Lite and find this module very
        >helpful..
        >
        >However I ran into a problem with complex datatypes and since I
        >couldn't
        >find any pointers in the documentation and during a web search I'll
        >try
        >to ask for help here..
        >
        >I get the following return data from a web service...
        >
        >----snip---
        >
        ><ANSWERS xsi:type="namesp2:ANSWERS"
        >SOAP-ENC:arrayType="namesp2:AnswerElement[2]"><answer
        >xsi:type="namesp2:AnswerElement" SOAP-ENC:arrayType="xsd:string[2]">
        > <dc:source xsi:type="xsd:string">sourceA</dc:source>
        > <dc:formatxsi:type="xsd:string">formatA</dc:format>
        ></answer>
        >
        ><answer xsi:type="namesp2:AnswerElement"
        >SOAP-ENC:arrayType="xsd:ur-type[5]">
        > <dc:source xsi:type="xsd:string">sourceB</dc:source>
        > <dc:format xsi:type="xsd:string">formatB</dc:format>
        ></answer>
        ></ANSWERS>
        >---/snip---
        >
        >If I use Data Dumper on the this
        >e.g.: print Dumper($rc->{'ANSWERS'});
        >
        >I get the following
        >
        > --- snip ---
        >Answers:$VAR1 = bless( [
        > bless( [
        > 'sourceA',
        > 'formatA',
        > ], 'AnswerElement' ),
        > bless( [
        > 'sourceB',
        > 'formatB',
        > ], 'AnswerElement' )
        > ], 'ANSWERS' );
        >--- /snip ---
        >
        >It seems that the labels 'dc:source' and 'dc:format' aren't accessible

        >any more.. (which is a little bit inconvenient should the order
        change.
        >. ;-)
        >
        >Is there a possibility to transform this type "AnswerElement" into a
        >hash?
        >
        >I'm sorry if I have missed something glaringly obvious but I would
        >appreciate any help
        >
        Hi Peter

        You seem to have a mismatch between defining the answer element as an
        array, SOAP-ENC:arrayType="xsd:string[2]", and wanting to see the
        result as a hash.
        If you remove the SOAP-ENC:arrayType attribute then S::L will
        deserialise answer as a blessed hash with the element names source and
        format.

        Good luck.

        Duncan Cameron








        ___________________________________________________________
        ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
      • Peter Mayr
        Hi Duncan, ... Thanks for your reply.. Unfortunately, since I am writing only the client I have no control over how the data is sent.. ;-( So I guess I have to
        Message 3 of 4 , Feb 17, 2005
          Hi Duncan,

          > You seem to have a mismatch between defining the answer element as an
          > array, SOAP-ENC:arrayType="xsd:string[2]", and wanting to see the
          > result as a hash.
          > If you remove the SOAP-ENC:arrayType attribute then S::L will
          > deserialise answer as a blessed hash with the element names source and
          > format.
          Thanks for your reply..
          Unfortunately, since I am writing only the client I have no control over
          how the data is sent.. ;-(

          So I guess I have to live with it?

          Best regards,

          Peter Mayr
        • Duncan Cameron
          ... Hi Peter I wonder what the producers of the message mean by having the answer element defined as an array of strings but each child element having
          Message 4 of 4 , Feb 18, 2005
            At 2005-02-18, 07:48:51 Peter Mayr <mayr@...> wrote:

            >Hi Duncan,
            >
            >> You seem to have a mismatch between defining the answer element as
            >>an
            >> array, SOAP-ENC:arrayType="xsd:string[2]", and wanting to see the
            >> result as a hash.
            >> If you remove the SOAP-ENC:arrayType attribute then S::L will
            >> deserialise answer as a blessed hash with the element names source
            >>and
            >> format.
            >Thanks for your reply..
            >Unfortunately, since I am writing only the client I have no control
            >over
            >how the data is sent.. ;-(
            >
            >So I guess I have to live with it?
            >
            Hi Peter

            I wonder what the producers of the message mean by having the answer
            element defined as an array of strings but each child element having
            different element names. To my (simplistic) view this seems
            inconsistent.
            i.e. why do the dc:source and dc:format elements have different names
            if they are meant to be simply entries of an array?
            Really, the element names should not be significant, rather their
            position in the sequence is what is significant.

            <answer
            xsi:type="namesp2:AnswerElement" SOAP-ENC:arrayType="xsd:string[2]">
            <dc:source xsi:type="xsd:string">sourceA</dc:source>
            <dc:formatxsi:type="xsd:string">formatA</dc:format>
            </answer>

            However you might be able to get around this by writing a custom
            deserialiser for the AnswerElement type, but I cannot see any examples
            of how to do that.

            Duncan








            ___________________________________________________________
            ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
          Your message has been successfully submitted and would be delivered to recipients shortly.