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

parsing request at mod_soap server

Expand Messages
  • sherwln
    Hi! I would like to know how to go through a request line by line at a mod_soap server if the request is something like this:
    Message 1 of 4 , Jan 26, 2002
    • 0 Attachment
      Hi!

      I would like to know how to go through
      a request line by line at a mod_soap server
      if the request is something like this:
      <m:PostFile xmlns:m="urn:RSource">
      <Record name="first.lastname" password="password">
      <File>
      <URL>http://webserver/temp/file1</URL>
      <Content>text</Content>
      </File>
      <File>
      <URL>http://webserver/temp/file2</URL>
      <Content>text</Content>
      </File>
      </Record>
      <Record name="second.lastname" password="password">
      <File>
      <URL>http://webserver/temp/file3</URL>
      <Content>text</Content>
      </File>
      <File>
      <URL>http://webserver/temp/file4</URL>
      <Content>text</Content>
      </File>
      </Record>
      </m:PostFile>


      I tried this:
      $envelope->dataof('//Record');
      but it doesn't point me to all 'File' elements
      underneath 'Record'

      and this:
      $envelope->dataof('//Record/File');
      but it doesn't point me to the 'Record'
      and attributes where it belongs

      and this
      $envelope->match('//Record');
      $envelope->valueof('[1]');
      $envelope->valueof('[2]');
      but it didn't help either because
      the _dump_ showed mixed up in 'File'
      (i.e. file1 is with file3 and file2 is
      with file4)

      $envelope->valueof('[1]') = {
      'Content' => 'text',
      'URL' => 'http://webserver/temp/file1'
      };
      $VAR2 = {
      'Content' => 'text',
      'URL' => 'http://webserver/temp/file3'
      };
      $envelope->valueof('[2]') = {
      'Content' => 'text',
      'URL' => 'http://webserver/temp/file2'
      };
      $VAR2 = {
      'Content' => 'text',
      'URL' => 'http://webserver/temp/file4'
      };


      $ perl -MSOAP::Lite -e'print $SOAP::Lite::VERSION'
      0.52


      TIA
      sherwin
    • Duncan Cameron
      Hello sherwln, This is a very frequently occuring question. Paul answered a similar question a few months ago, look here =
      Message 2 of 4 , Jan 27, 2002
      • 0 Attachment
        Hello sherwln,

        This is a very frequently occuring question. Paul answered a similar
        question a few months ago, look here =>
        http://groups.yahoo.com/group/soaplite/message/746

        Nevertheless it does seem ridiculously complicated to access the
        elements in the 'natural' way.
        As you have seen, when you take valueof() or dataof(), SOAP::Lite's
        default deserialisation causes repeating elements to be 'squashed' and
        only the final one selected.

        After fiddling around here's what I came up with based on your example.
        It navigates through the SOM by element position, so that there are no
        problems with dataof()/valueof(). However, there _must_ be a better way!

        my $som = SOAP::Deserializer->deserialize($xml);
        # Iterate through all child elements of PostFile
        for ($i = 1; my $record = $som->dataof("/PostFile/[$i]"); $i++) {
        print join(' ', $record->name, $record->attr->{name},
        $record->attr->{password}), "\n";
        # Iterate through all child elements of the current Record element
        for ($j = 1; my $file = $som->dataof("/PostFile/[$i]/[$j]"); $j++) {
        print join(' ', $file->name, $file->value->{Content},
        $file->value->{URL}), "\n";
        }
        }



        Regards,
        Duncan Cameron

        On 2002-01-27 sherwln <sherwln@...> wrote:
        >Hi!
        >
        >I would like to know how to go through
        >a request line by line at a mod_soap server
        >if the request is something like this:
        ><m:PostFile xmlns:m="urn:RSource">
        > <Record name="first.lastname" password="password">
        > <File>
        > <URL>http://webserver/temp/file1</URL>
        > <Content>text</Content>
        > </File>
        > <File>
        > <URL>http://webserver/temp/file2</URL>
        > <Content>text</Content>
        > </File>
        > </Record>
        > <Record name="second.lastname" password="password">
        > <File>
        > <URL>http://webserver/temp/file3</URL>
        > <Content>text</Content>
        > </File>
        > <File>
        > <URL>http://webserver/temp/file4</URL>
        > <Content>text</Content>
        > </File>
        > </Record>
        ></m:PostFile>
        >
        >
        >I tried this:
        >$envelope->dataof('//Record');
        >but it doesn't point me to all 'File' elements
        >underneath 'Record'
        >
        >and this:
        >$envelope->dataof('//Record/File');
        >but it doesn't point me to the 'Record'
        >and attributes where it belongs
        >
        >and this
        >$envelope->match('//Record');
        >$envelope->valueof('[1]');
        >$envelope->valueof('[2]');
        >but it didn't help either because
        >the _dump_ showed mixed up in 'File'
        >(i.e. file1 is with file3 and file2 is
        > with file4)
        >
        >$envelope->valueof('[1]') = {
        > 'Content' => 'text',
        > 'URL' => 'http://webserver/temp/file1'
        >};
        >$VAR2 = {
        > 'Content' => 'text',
        > 'URL' => 'http://webserver/temp/file3'
        >};
        >$envelope->valueof('[2]') = {
        > 'Content' => 'text',
        > 'URL' => 'http://webserver/temp/file2'
        >};
        >$VAR2 = {
        > 'Content' => 'text',
        > 'URL' => 'http://webserver/temp/file4'
        >};
        >
        >
        >$ perl -MSOAP::Lite -e'print $SOAP::Lite::VERSION'
        >0.52
        >
        >
        >TIA
        >sherwin
      • Richard Letts
        ... the fact the question comes up so often indicates that the current behavoir is not what is desired, and we need something to override the behavoir. I d
        Message 3 of 4 , Jan 27, 2002
        • 0 Attachment
          On Sun, 27 Jan 2002, Duncan Cameron wrote:

          > Hello sherwln,
          >
          > This is a very frequently occuring question. Paul answered a similar
          > question a few months ago, look here =>
          > http://groups.yahoo.com/group/soaplite/message/746

          the fact the question comes up so often indicates that the current
          behavoir is not what is desired, and we need something to override the
          behavoir. I'd like a setting where I can say 'parse this as a list, and
          not as a hash'. I'd write it myself except the use of map has obfusticated
          the code to the point where I cannot understand what it is trying to do.

          > After fiddling around here's what I came up with based on your example.
          > It navigates through the SOM by element position, so that there are no
          > problems with dataof()/valueof(). However, there _must_ be a better way!

          I modified Lite.pm, after about where the comment
          # $name is not used here ....
          ....
          # don't use class/type if anyType/ur-type is speficied

          to say something like:
          # $name is not used here ....
          ....

          $class='foo' if ($name eq '{http://www.illuin.org/Servicea}/foo')
          # don't use class/type if anyType/ur-type is specified

          and adding later on (still in the SOAP::Deserializer Package)

          # I don't know why this works, but it does.
          sub as_foo {
          my $self=shift;
          [ map { scalar(($self->decode_object($_))[1] } &{$_[3] || []} ];
          }
          [[ thanks to Paul for the as_foo code -- but I couldn't figure out the
          proper way to get it invoked]]

          now things of the form
          <foo>
          <bar>one</bar>
          <bar>two</bar>
          <bar>three</bar>
          </foo>

          get deserialized properly.

          I'd tried to figure out how to tell soap::Lite the right information
          about the <foo> tag but given up as being impossible.

          RjL
          +--------------------------+
          | richard@... | ... and the light of the Lamps of the
          +--------------------------+ Valar flowed out over the Earth
        • sherwln
          [Sorry if it s already a duplicate. My opera suddenly closed and I have no idea if it was already sent]--- In soaplite@y..., Duncan Cameron
          Message 4 of 4 , Jan 27, 2002
          • 0 Attachment
            [Sorry if it's already a duplicate. My opera suddenly closed
            and I have no idea if it was already sent]

            --- In soaplite@y..., Duncan Cameron <dcameron@b...> wrote:
            > This is a very frequently occuring question. Paul answered a similar
            > question a few months ago, look here =>
            > http://groups.yahoo.com/group/soaplite/message/746
            >

            Thanks. I already read that post while I was digging through
            the archive before I asked for help. It just didn't give me
            _enough_ hint to solve my long problem.

            Anyway, your post really helped. I appreciate it.

            > After fiddling around here's what I came up with based on your example.
            > It navigates through the SOM by element position, so that there are no
            > problems with dataof()/valueof(). However, there _must_ be a better way!
            >
            > my $som = SOAP::Deserializer->deserialize($xml);
            > # Iterate through all child elements of PostFile
            > for ($i = 1; my $record = $som->dataof("/PostFile/[$i]"); $i++) {
            > print join(' ', $record->name, $record->attr->{name},
            > $record->attr->{password}), "\n";
            > # Iterate through all child elements of the current Record element
            > for ($j = 1; my $file = $som->dataof("/PostFile/[$i]/[$j]"); $j++) {
            > print join(' ', $file->name, $file->value->{Content},
            > $file->value->{URL}), "\n";
            > }
            > }
            >

            I modified your code a little bit and
            I'm posting it for the newbies like me that
            might come across the same situation. ¦:¬)

            package RSource;

            use strict;
            use vars qw(@ISA);
            @ISA = qw(SOAP::Server::Parameters); # to get envelope

            sub PostFile {
            my $self = shift;
            my $envelope = pop;
            my $header = $envelope->header;

            # Iterate through all child elements of PostFile
            for (my $i = 1; my $record = $envelope->dataof("//PostFile/[$i]"); $i++) =
            {
            print join(' ', $record->name, $record->attr->{name},
            $record->attr->{password}), "\n";

            # Iterate through all child elements of the current Record element
            for (my $j = 1; my $file = $envelope->dataof("//PostFile/[$i]/[$j]"); $=
            j++) {
            print join(' ', $file->name, $file->value->{Content},
            $file->value->{URL}), "\n";
            }
            }

            # Other stuff here
            }

            > Regards,
            > Duncan Cameron
            >
            > On 2002-01-27 sherwln <sherwln@y...> wrote:
            > ><m:PostFile xmlns:m="urn:RSource">
            > > <Record name="first.lastname" password="password">
            > > <File>
            > > <URL>http://webserver/temp/file1</URL>
            > > <Content>text</Content>
            > > </File>
            > > <File>
            > > <URL>http://webserver/temp/file2</URL>
            > > <Content>text</Content>
            > > </File>
            > > </Record>
            > > <Record name="second.lastname" password="password">
            > > <File>
            > > <URL>http://webserver/temp/file3</URL>
            > > <Content>text</Content>
            > > </File>
            > > <File>
            > > <URL>http://webserver/temp/file4</URL>
            > > <Content>text</Content>
            > > </File>
            > > </Record>
            > ></m:PostFile>

            --
            sherwin
          Your message has been successfully submitted and would be delivered to recipients shortly.