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

Re: [soaplite] processing complex som

Expand Messages
  • Doug Fulton
    Thanks, Duncan. The former method works. The latter method looks promising and I probably need to get it working since I am processing a large XML document
    Message 1 of 4 , Apr 2, 2002
    • 0 Attachment
      Thanks, Duncan. The former method works. The latter method looks
      promising and I probably need to get it working since I am processing a
      large XML document and the performance of repeatedly traversing the SOM
      is not great. I found the example, customxml.pl, under examples/XML/.
      I am having trouble, however, with the appropriate call to set up my $d
      (Deserializer) in the first place with the XML returned by the server.
      Currently, I get the SOM via

      my $soap = SOAP::Lite
      -> uri($NS)
      -> proxy($HOST)
      -> namespace('s');
      my $som = $soap
      ->call('hc:webStatsJobs');

      Cheers,
      Doug

      On Friday, March 29, 2002, at 06:50 PM, Duncan Cameron wrote:

      > 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:
      >>
      >> <jobs>
      >> <job>
      >> <jobID> 1 </jobID>
      >> <jobItems>
      >> <jobItem>a<jobItem>
      >> <jobItem>b<jobItem>
      >> ...
      >> </jobItems>
      >> <job>
      >> ...
      >> <jobs>
      >>
      >> 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";
      > }
      > }
      >
      >
      > Regards,
      > Duncan Cameron
      >
      >
    • Paul Kulchenko
      Hi, Doug! ... probably something like this will work: my $soap = SOAP::Lite - uri($NS) - proxy($HOST) - deserializer(SOAP::Custom::XML::Deserializer- new)
      Message 2 of 4 , Apr 2, 2002
      • 0 Attachment
        Hi, Doug!

        --- Doug Fulton <dfulton@...> wrote:
        > I am having trouble, however, with the appropriate call to set up
        > my $d
        > (Deserializer) in the first place with the XML returned by the
        > server. Currently, I get the SOM via
        >
        > my $soap = SOAP::Lite
        > -> uri($NS)
        > -> proxy($HOST)
        > -> namespace('s');
        > my $som = $soap
        > ->call('hc:webStatsJobs');

        probably something like this will work:

        my $soap = SOAP::Lite
        -> uri($NS)
        -> proxy($HOST)
        -> deserializer(SOAP::Custom::XML::Deserializer->new)
        -> namespace('s') # << why do you need that?
        ;
        my $som = $soap
        ->call('hc:webStatsJobs');

        my $d = $som->result;

        and then use $d as in Duncan's example.

        Best wishes, Paul.

        __________________________________________________
        Do You Yahoo!?
        Yahoo! Tax Center - online filing with TurboTax
        http://http://taxes.yahoo.com/
      Your message has been successfully submitted and would be delivered to recipients shortly.