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

Problems with Arrays only returning 1 element

Expand Messages
  • Andy Kelk
    Hi, I have a document which has a snipped structured something like this:
    Message 1 of 3 , Dec 19, 2002
    • 0 Attachment
      Hi,

      I have a document which has a snipped structured something like this:

      <categoryElements
      xmlns:namesp1="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="namesp1:categoryArray" namesp1:arrayType="xsd:string[2]">
      <category xsi:type="xsd:string">@1020</category>
      <category xsi:type="xsd:string">@1006</category>
      </categoryElements>


      The code I want to use to get this info is like this:

      @elements = $product->match("//categoryElements/category");
      $tot = scalar(@elements);
      for ($k = 0; $k < $tot; $k++)
      {
      $buff .= "catref$k\t" . $elements[$k]->valueof() . "\t";
      }

      It doesn't throw any errors, but I only ever get catref0 returned with
      the correct value. I never get the second element. The same is true of
      my other arrays.
      I have only thrown myself into SOAP::Lite recently so I may have made an
      elementary mistake (I probably have). But I have searched this group and
      many others to try and find a solution and feel I have hit a brick wall.
      Any help would be much appreciated.

      Thanks

      Andy


      --
      Andy Kelk
      Head of Integration, Venda
      andy@...
    • Mental Patient
      ... ... I had this exact problem. I dont use autodispatch or dispatch_from, so my style looks a little different from yours, but - result() only returns
      Message 2 of 3 , Dec 20, 2002
      • 0 Attachment
        On Thu, 2002-12-19 at 10:24, Andy Kelk wrote:
        > Hi,
        >
        > I have a document which has a snipped structured something like this:
        >
        > <categoryElements
        > xmlns:namesp1="http://schemas.xmlsoap.org/soap/encoding/"
        > xsi:type="namesp1:categoryArray" namesp1:arrayType="xsd:string[2]">
        > <category xsi:type="xsd:string">@1020</category>
        > <category xsi:type="xsd:string">@1006</category>
        > </categoryElements>
        >
        >
        > The code I want to use to get this info is like this:
        >
        > @elements = $product->match("//categoryElements/category");

        <snip>

        > It doesn't throw any errors, but I only ever get catref0 returned with
        > the correct value. I never get the second element. The same is true of
        > my other arrays.
        > I have only thrown myself into SOAP::Lite recently so I may have made an
        > elementary mistake (I probably have). But I have searched this group and
        > many others to try and find a solution and feel I have hit a brick wall.
        > Any help would be much appreciated.

        I had this exact problem. I dont use autodispatch or dispatch_from, so
        my style looks a little different from yours, but ->result() only
        returns the first result. To get a list back I needed to call
        ->paramsall().

        example:
        $psoap->call('components',$obj,$c,$c2)->result();

        my @list = $psoap->call('components',$obj)->paramsall();

        The components method on $obj takes a list of 'things' and holds it.
        Subsequent calls return the stored list. ITs just a get/set for
        'things'. The above illustrates me storing a list, then getting it back
        later.



        Yeah, my style is pretty horrific, but this should get you moving in the
        right direction.

        Over all I've found my archive of messages sent to this list to be
        invaluable in troubleshooting issues I've run into.



        --

        Mental (Mental@...)


        The Riddle of Epicurus

        Is God willing to prevent evil, but not able? Then he is not omnipotent.
        Is he able, but not willing? Then he is malevolent.
        Is he both able and willing? Then whence cometh evil?
        Is he neither able nor willing? Then why call him God?

        http://www.positiveatheism.org/

        CARPE NOCTEM, QUAM MINIMUM CREDULA POSTERO.

        GPG public key: http://www.neverlight.com/pas/Mental.asc
      • Paul Kulchenko
        Hi Andy, ... It doesn t suppose to work this way; match() remembers matched dataset internally and returns SOAP::SOM object, so that subsequent dataof/valueof
        Message 3 of 3 , Dec 20, 2002
        • 0 Attachment
          Hi Andy,

          > It doesn't throw any errors, but I only ever get catref0 returned
          > with
          > the correct value. I never get the second element. The same is true
          It doesn't suppose to work this way; match() remembers matched
          dataset internally and returns SOAP::SOM object, so that subsequent
          dataof/valueof calls can use this value. Regardless of the context
          (list/scalar) result is always the same: one object. That's why
          scalar(@elements) always returns '1', even though there are more
          elements.

          You can change your code to smth like this:

          @elements = $product->match("//categoryElements/category")->valueof;

          -- OR --

          @elements = $product->valueof("//categoryElements/category");

          and remove valueof() from:

          $buff .= "catref$k\t" . $elements[$k] . "\t";

          dataof/valueof('something') are shortcuts for
          match('something')>dataof/valueof(). Hope that helps.

          Best wishes, Paul.

          --- Andy Kelk <andy@...> wrote:
          > Hi,
          >
          > I have a document which has a snipped structured something like
          > this:
          >
          > <categoryElements
          > xmlns:namesp1="http://schemas.xmlsoap.org/soap/encoding/"
          > xsi:type="namesp1:categoryArray" namesp1:arrayType="xsd:string[2]">
          > <category xsi:type="xsd:string">@1020</category>
          > <category xsi:type="xsd:string">@1006</category>
          > </categoryElements>
          >
          >
          > The code I want to use to get this info is like this:
          >
          > @elements = $product->match("//categoryElements/category");
          > $tot = scalar(@elements);
          > for ($k = 0; $k < $tot; $k++)
          > {
          > $buff .= "catref$k\t" . $elements[$k]->valueof() . "\t";
          > }
          >
          > It doesn't throw any errors, but I only ever get catref0 returned
          > with
          > the correct value. I never get the second element. The same is true
          > of
          > my other arrays.
          > I have only thrown myself into SOAP::Lite recently so I may have
          > made an
          > elementary mistake (I probably have). But I have searched this
          > group and
          > many others to try and find a solution and feel I have hit a brick
          > wall.
          > Any help would be much appreciated.
          >
          > Thanks
          >
          > Andy
          >
          >
          > --
          > Andy Kelk
          > Head of Integration, Venda
          > andy@...
          >
          > ------------------------ 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! Mail Plus - Powerful. Affordable. Sign up now.
          http://mailplus.yahoo.com
        Your message has been successfully submitted and would be delivered to recipients shortly.