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

parsing undeclared array / patch proposal

Expand Messages
  • wackerl@iatms11.iatm.tuwien.ac.at
    it is apparently possible (though maybe not legal xml) to bild an array without declaring an arraytype. something like this chunk: x1 x2
    Message 1 of 2 , Dec 29, 2003
    • 0 Attachment
      it is apparently possible (though maybe not legal xml)
      to bild an array without declaring an arraytype.
      something like this chunk:
      <A>
      <B>x1</B>
      <B>x2</B>
      <B>x3</B>
      </A>
      but when this is fed to a SOAP::Lite server, only the
      last <B> element is put into the hash.

      [XML::Generator produces xml like this, XmlSpy does,...
      so it's a reality we have to cope with, i'd say]

      i dug into the source and found the line
      %$res = map {$self->decode_object($_)} @{$children || []};
      in SOAP::Deserializer::decode_value
      and replaced it with
      foreach my $child (@{$children || []})
      {
      my( $child_name, $child_data ) = $self->decode_object($child);
      if( !exists $res->{$child_name} )
      {
      #first entry; single entry
      $res->{$child_name} = $child_data;
      }
      elsif( ref($res->{$child_name}) eq 'ARRAY')
      {
      #third entry; adding to array
      push @{$res->{$child_name}}, $child_data;
      }
      else
      {
      #second entry; conversion from single to array
      $res->{$child_name} = [$res->{$child_name}, $child_data];
      }
      }
      which retains the array (and doesn't break to much else, i hope)

      here's my test suite
      send_file.pl just sends the file Beispiel.xml to afz_server.pl
      and prints the result.
    • wackerl@iatms11.iatm.tuwien.ac.at
      no attachments. oh, all right... ... #!/usr/bin/perl use LWP::UserAgent; $payload =
      Message 2 of 2 , Dec 29, 2003
      • 0 Attachment
        no attachments. oh, all right...

        ----8<---- send_file.pl ----8<----

        #!/usr/bin/perl

        use LWP::UserAgent;

        $payload = <<eoXML;
        <?xml version='1.0' encoding='UTF-8'?>
        <SOAP-ENV:Envelope
        xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/1999/XMLSchema"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <SOAP-ENV:Body>
        <namesp1:doTransaction xmlns:namesp1="http://ella.lokales.netz/afz">
        <AFZ_MELDUNG>
        eoXML

        open( XML, '<Beispiel.xml' ) || die $!;
        undef $/;
        $data = <XML>;
        close XML;

        $payload .= $data;
        $payload .= <<eoXML;
        </AFZ_MELDUNG>
        </namesp1:doTransaction>
        </SOAP-ENV:Body>
        </SOAP-ENV:Envelope>
        eoXML

        open( XML, '>afz_meldung_debug.xml' );
        print XML $payload;
        close XML;

        print 'payload length: ', length( $payload ), "\n";

        $ua = LWP::UserAgent->new;
        $header = new HTTP::Headers('Content-Type'=>'text/xml');
        $request = new HTTP::Request(
        'POST',
        'http://ella.lokales.netz/pub/soap/cgi-bin/afz_server.pl',
        $header,
        $payload
        );
        $response = $ua->request($request);
        $content = $response->content;
        #$content =~ s|</([\s\w]+)>|</$1>\n|g;
        $content =~ s|(?<!=)>|>\n|g;

        print "\n\ncode: ", $response->code;
        print "\n\nmessage: ", $response->message;
        print "\n\nheader: ", $response->header;
        print "\n\ncontent: ", $content;
        print "\n";


        ----8<---- afz_server.pl ----8<----

        #!/usr/bin/perl -w

        $SOAP::Constants::DO_NOT_USE_XML_PARSER = 1;
        my $server = SOAP::Transport::HTTP::CGI
        -> objects_by_reference( 'afz' )
        -> dispatch_to('afz')
        -> handle()
        ;

        package afz;

        use vars qw(@ISA $iTANSequence);
        BEGIN
        {
        @ISA = qw(SOAP::Server::Parameters);
        }
        use strict;
        use Data::Dumper;

        sub debug
        {
        my( $self, @params ) = @_;

        my $s = join( '~~~', 's', 'self=', $self,
        'params:', @params,
        '#0=', %{$params[0]}, 'e' );

        return
        SOAP::Data->name( Params => $s ),
        SOAP::Data->name( PerlVersion => $] ),
        SOAP::Data->name( INC => [@INC] )
        ;
        }

        sub doTransaction
        {
        my( $self, @params ) = @_;
        my $data = \%{$params[0]};
        my @aErrorCodes;

        return
        SOAP::Data->type('string')->name('xx2'=>Data::Dumper->Dumper($data));

        }

        1;


        ----8<---- Beispiel.xml ----8<----

        <VERSION>1.1</VERSION>
        <TAN>314159265359</TAN>
        <SENDER>
        <IDENTIFICATION>
        <Value>1234567890123</Value>
        <Type>EAN</Type>
        <Authority/>
        </IDENTIFICATION>
        <PARTYTYPE>LEGAL</PARTYTYPE>
        <PARTYNAME1>Testfirma</PARTYNAME1>
        <PARTYNAME2/>
        <PARTYNAME3/>
        <PARTYNAME4/>
        <ADRESS>
        <PARTYPOB/>
        <PARTYSTR1>Hauptstrasse</PARTYSTR1>
        <PARTYSTR2/>
        <PARTYSTRNUM>1</PARTYSTRNUM>
        <PARTYSTRNRX/>
        <PARTYCOUNTRY>AT</PARTYCOUNTRY>
        <PARTYPOSTCODE>1010</PARTYPOSTCODE>
        <PARTYTOWN1>Wien</PARTYTOWN1>
        <PARTYTOWN2/>
        </ADRESS>
        <PARTYCONTTEL/>
        <PARTYCONTFAX/>
        <PARTYCONTMOBILE/>
        <PARTYCONTEM/>
        </SENDER>
        <BERICHTSJAHR>2003</BERICHTSJAHR>
        <MELDENDER>
        <IDENTIFICATION>
        <Value>1234567890123</Value>
        <Type>EAN</Type>
        </IDENTIFICATION>
        <PARTYTYPE>LEGAL</PARTYTYPE>
        <PARTYNAME1>Testfirma</PARTYNAME1>
        <ADRESS>
        <PARTYSTR1>Hauptstrasse</PARTYSTR1>
        <PARTYSTRNUM>1</PARTYSTRNUM>
        <PARTYCOUNTRY>AT</PARTYCOUNTRY>
        <PARTYPOSTCODE>1010</PARTYPOSTCODE>
        <PARTYTOWN1>Wien</PARTYTOWN1>
        </ADRESS>
        </MELDENDER>
        <HSTUEB>
        <AFZ_UEBERNAHME>
        <AFZ>
        <MARKE>VW</MARKE>
        <TYPE>Golf</TYPE>
        <BAUJAHR>2000</BAUJAHR>
        <SENDERID>1</SENDERID>
        </AFZ>
        <UEBERNAME_DATUM>2003-01-01</UEBERNAME_DATUM>
        <UEBERGEBER>
        <PARTYTYPE>NATURAL</PARTYTYPE>
        <PARTYNAME1>Zola</PARTYNAME1>
        <PARTYNAME2/>
        <PARTYNAME3/>
        <PARTYNAME4/>
        <ADRESS>
        <PARTYPOB/>
        <PARTYSTR1>Boulevard</PARTYSTR1>
        <PARTYSTR2/>
        <PARTYSTRNUM>1</PARTYSTRNUM>
        <PARTYSTRNRX/>
        <PARTYCOUNTRY>FR</PARTYCOUNTRY>

        <PARTYPOSTCODE>12345</PARTYPOSTCODE>
        <PARTYTOWN1>Paris</PARTYTOWN1>
        <PARTYTOWN2/>
        </ADRESS>
        <PARTYCONTTEL/>
        <PARTYCONTFAX/>
        <PARTYCONTMOBILE/>
        <PARTYCONTEM/>
        </UEBERGEBER>
        </AFZ_UEBERNAHME>
        <AFZ_UEBERNAHME>
        <AFZ>
        <MARKE>AUDI</MARKE>
        <TYPE>xyz 666</TYPE>
        <BAUJAHR>2000</BAUJAHR>
        <SENDERID>2</SENDERID>
        </AFZ>
        <UEBERNAME_DATUM>2003-02-02</UEBERNAME_DATUM>
        <UEBERGEBER>
        <PARTYTYPE>NATURAL</PARTYTYPE>
        <PARTYNAME1>Hugo</PARTYNAME1>
        <ADRESS>
        <PARTYSTR1>Boulevard</PARTYSTR1>
        <PARTYSTRNUM>1</PARTYSTRNUM>
        <PARTYCOUNTRY>FR</PARTYCOUNTRY>

        <PARTYPOSTCODE>12345</PARTYPOSTCODE>
        <PARTYTOWN1>Paris</PARTYTOWN1>
        </ADRESS>
        </UEBERGEBER>
        </AFZ_UEBERNAHME>
        <AFZ_UEBERNAHME>
        <AFZ>
        <MARKE>HONDA</MARKE>
        <TYPE>S2000</TYPE>
        <BAUJAHR>1990</BAUJAHR>
        <SENDERID>2</SENDERID>
        </AFZ>
        <UEBERNAME_DATUM>2003-03-03</UEBERNAME_DATUM>
        <UEBERGEBER>
        <PARTYTYPE>NATURAL</PARTYTYPE>
        <PARTYNAME1>Hugo</PARTYNAME1>
        <ADRESS>
        <PARTYSTR1>Boulevard</PARTYSTR1>
        <PARTYSTRNUM>1</PARTYSTRNUM>
        <PARTYCOUNTRY>FR</PARTYCOUNTRY>

        <PARTYPOSTCODE>12345</PARTYPOSTCODE>
        <PARTYTOWN1>Paris</PARTYTOWN1>
        </ADRESS>
        </UEBERGEBER>
        </AFZ_UEBERNAHME>
        </HSTUEB>
      Your message has been successfully submitted and would be delivered to recipients shortly.