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

3048Re: [soaplite] Re: SOAP::SOM array of arrays

Expand Messages
  • Duncan Cameron
    Oct 8, 2003
    • 0 Attachment
      At 13:21:00 on 2003-10-08 teden <the@...> wrote:

      >I am beginning to get it. My code below is doing exactly what I asked
      >it to - get the som tree for all A elements, then get the som tree
      >for all B elements. What I want are all the B elements for a given A
      >element. It seems I cannot do what it is I want to do. SOAP::SOM->
      >match, dataof and valueof trim the SOM tree to a subset specified in
      >the path given as an argument. When processing the inner array, it
      >seems I cannot match it to its parent element, a key requirement.
      >When the documentation says that the SOAP::SOM
      >methods "match", "dataof", and "valeuof" take a simple XPATH type
      >syntax, I expected to be able to specify something like
      > '//A[1]/B[1]'
      >to get the first B element nested within the first A element. Alas, I
      >cannot. Can this be a formal request for an enhancement? In the
      >meantime, I either need to look at creating a custom deserializer,
      >or - heaven forbid - another language.
      One way is to iterate through the children at each level, like this:

      my $xml = <<'END';
      <C>c stuff </C>
      <C>c stuff </C>

      my $som = SOAP::Deserializer->deserialize($xml);
      # Iterate through all child elements of <root>
      for ($i = 1; my $a = $som->dataof("/root/[$i]"); $i++) {
      next unless $a->name eq 'A';
      # Iterate through all child elements of the current <A> element
      for ($j = 1; my $b = $som->dataof("/root/[$i]/[$j]"); $j++) {
      next unless $b->name eq 'B';
      print $b->value, "\n";



    • Show all 6 messages in this topic