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

1377Re: [soaplite] processing complex som

Expand Messages
  • Duncan Cameron
    Mar 29, 2002
      On 2002-03-29 Doug Fulton wrote:
      >My resuls structure has increased in complexity and I am having
      >difficulty processing it. I have something like the following:
      > <job>
      > <jobID> 1 </jobID>
      > <jobItems>
      > <jobItem>a<jobItem>
      > <jobItem>b<jobItem>
      > ...
      > </jobItems>
      > <job>
      > ...
      >I tried:
      >my @jobs = $som->valueof('//jobs');
      >foreach $job (@jobs) {
      > print $job->{'jobID'}."\n";
      > print $_->{'jobItem'}
      > for $job->{'jobItems'};
      >I get all the jobs (jobIDs), but I only get one jobItem per job --the
      >last one, I believe.
      >Thoughts on this?
      You need to do another valueof() on $job to get the jobItems, something like this
      is long-winded but seems to do what you want:

      for ($i = 1; my $job = $som->valueof("/jobs/[$i]"); $i++) {
      print $job->{jobID} . "\n";
      for ($j = 1; my $jobItem = $som->valueof("/jobs/[$i]/jobItems/[$j]"); $j++) {
      print $jobItem . "\n"

      The re-evaluation of valueof() is necessary because SOAP::Lite by default 'squashes'
      elements with the same name. This was discussed on the list a few months ago but
      I can't find it in the archives.

      I'm not sure where I saw it described but a neater way is to use the
      SOAP::Custom::XML::Deserializer, each attribute or sub-element seems to be
      accessible through a method:

      for $job ($d->job) {
      print $job->jobID, "\n";
      my $items = $job->jobItems;
      for $item ($items->jobItem) {
      print $item->value, "\n";

      Duncan Cameron
    • Show all 4 messages in this topic