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

4158Re: [soaplite] dataof() use with index

Expand Messages
  • Duncan Cameron
    Nov 6, 2004
      On 2004-11-06 at 00:26:35 Martin Naskovski wrote:

      >Hi - I have this code:
      > $som->match('/Envelope/Body/[1]');
      > my @evtList;
      > my $idx = 1;
      > while ( defined $som->dataof("[$idx]") ) {
      >my $eventXML = $som->dataof("[$idx]/event");
      > }
      >Which basically takes MANY <regAPI> </regAPI>, elements in my XML
      >and the $idx is used to access each <regAPI> / </regAPI> pair as an
      >by using 'dataof()' (or valueof() if you wish).
      >The <regAPI> / <.regAPI> contains this:
      > <event .... />
      >My problem is, when I have a SOAP call which returns JUST ONE <regAPI>
      ></regAPI> , the above code does NOT work, so in order to get the
      >part, I have to do:
      >everytime I have a SINGLE <regAPI> pair.
      >Why cant I just process even a SINGLE element as a list through my
      >loop, with only a signle iteration through it, and return a LIST with
      >element in it?
      >Am I missing something, or is this not possible wit hthe SOAP::Lite
      There must be something wrong with the parts of the code that you have
      not shown. The following example works for 0, 1 or many regAPI elements,
      assuming that your xml is something like

      <regAPI ID='regAPI 1'>
      <event eventName='event 1' eventID='1' />
      <regAPI ID='regAPI 2'>
      <event eventName='event 2' eventID='2' />
      <regAPI ID='regAPI 3'>
      <event eventName='event 3' eventID='3' />

      my $idx = 1;
      while ( my $regAPI = $som->dataof("[$idx]") ) {
      my $eventXML = $som->dataof("[$idx]/event");
      print $regAPI->attr->{ID}, ' ', $eventXML->attr->{eventName}, "\n";
      If you don't need any information from the regAPI elements then you can
      simply get all the event elements

      my @event = $som->dataof('//event');

    • Show all 2 messages in this topic