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

SOAP::SOM::match(), valueof(), headerof() and style/efficience

Expand Messages
  • Alexandre Maret
    hello This is a question about code style & efficience. I need to iterate over a list of elements. I need to use valueof() as well as headerof(), since I have
    Message 1 of 1 , Jul 2, 2001
    • 0 Attachment
      hello

      This is a question about code style & efficience. I need to iterate over a
      list of elements. I need to use valueof() as well as headerof(), since I
      have to fetch some attributes.

      My data looks like:

      <response>
      <summary name="zero">
      <data1> ... </data1>
      <data2> ... </data2>
      </summary>

      <summary name="one">
      <data1> ... </data1>
      <data2> ... </data2>
      </summary>
      ...
      </response>

      $response->valueof('//summary') gives me back a list. that's fine, I can
      play with the data.

      $response->headerof('//summary') gives me back a list. that's fine too, I
      can play with the 'summary' elements attributes.

      However, $response->match('//summary') doesn't give me back a list I can
      iterate over. I want to avoid working with 2 lists (headers, values) and
      use a nice looking idiom, like:

      [broken code]

      foreach $node (@response->match('//summary')) {
      my $attr = $node->headerof()->attr();
      my $summary = $node->valueof();
      my $name = $attr->{'name'};
      doSomethingWith $summary->{'data1'};
      ...
      }

      [/broken code]

      but don't know how to do it (if possible)... could anyone give me an
      advice pls ?



      It seems possible to do what I want (more or less) this way:

      for (xxx in range) {
      $som->match('/Envelope/Body/response/[xxx]'); # xxx as child num
      ... $som->valueof ...;
      ... $som->headerof ...;
      }

      but this isn't very nice... requiring the generation of a new match
      pattern at each iteration. What about efficiency? Any comment about this?

      thanks

      alex, hoping he's not missed something obvious
    Your message has been successfully submitted and would be delivered to recipients shortly.