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

Nested data and non unique tags

Expand Messages
  • Timothy Legge
    Hi I have a web service that I connect to as follows and dump the results to the screen. The issue is that the data received from the web service includes the
    Message 1 of 3 , May 3 12:41 PM
    • 0 Attachment

      Hi

       

      I have a web service that I connect to as follows and dump the results to the screen.  The issue is that the data received from the web service includes the same XML tag multiple times in the XML.  However I do not seem to be able to access that multiple iterations of that tag:

       

      I am not a Perl expert (or even a novice really) this is a learning exercise.  I am just trying to figure out whether this is an issue with the use of the WDSL in SOAP::Lite, the way DUMPER outputs nested data etc…

       

      The perl script, correct Web Service response and the SOAP:Lite data for the response are below.

       

      Any ideas?

       

      =======================

      #!/usr/bin/perl

       

      use strict;

      use diagnostics;

      use warnings;

       

      use Data::Dumper;

       

      use SOAP::Lite;

      my $source = "sourcename";

      my $destination = "destinationname";

      my $systemmode = "Development";

       

      my $wsdl = "http://servername/beti/beti.asmx?WSDL";

      my $query = SOAP::Lite->service($wsdl);

       

      my $results = $query->GetOfficialStuff(

              $source,

              $destination,

              $systemmode);

       

      print Dumper($results);

      ==============================

      That web service returns an XML doc that looks like:

       

      <?xml version="1.0" encoding="utf-8"?>

      <GDEnvelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://domain.com/">

        <Header>

          <Source>sourcename</Source>

          <Destination>destinationname</Destination>

          <SystemMode>Development</SystemMode>

          <Err>

            <ErrorCode>0</ErrorCode>

          </Err>

        </Header>

        <GDs>

          <GD>

            <G>GName1</G>

            <Num>103</Num>

            <Day>0</Day>

            <LastDay>true</LastDay>

          </GD>

          <GD>

            <G>GName2</G>

            <Num>616</Num>

            <Day>0</Day>

            <LastDay>true</LastDay>

          </GD>

        </GDs>

      </GDEnvelope>

      =================================

      The result of the Dumper command is:

       

      $VAR1 = {

                'GDs' => {

                               'GD' => {

                                             'Num' => '616',

                                             'Day' => '0',

                                             'LastDay' => 'true',

                                             'G' => 'GName2'

                                           }

                             },

                'Header' => {

                            'SystemMode' => 'Development',

                            'Destination' => 'sourcename',

                            'Source' => 'destinationname',

                            'Err' => {

                                     'ErrorCode' => '0'

                                   }

                          }

              };

       

       

      Tim

      **********************************************************************

      This E-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary, confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender and erase this E-mail message immediately.

      Le present message electronique (y compris les pieces qui y sont annexees, le cas echeant) s'addresse au destinataire indique et peut contenir des renseignements de caractere prive ou confidentiel. Si vous n'etes pas le destinataire de ce document, nous vous signalons qu'il est strictement interdit de le diffuser, de le distribuer ou de le reproduire. Si ce message vous a ete transmis par erreur, veuillez en informer l'expediteur et le supprimer immediatement.

    • Eric Bridger
      Try adding: $query- want_som(1); to your script. Then see: http://www.majordojo.com/soaplite/2003/08/parsing_a_resul.html on how to access array elements using
      Message 2 of 3 , May 3 2:08 PM
      • 0 Attachment
        Try adding:
        $query->want_som(1);
        to your script.

        Then see:
        http://www.majordojo.com/soaplite/2003/08/parsing_a_resul.html

        on how to access array elements using the SOM object.

        HTH.
        Eric

        On Wed, 2006-05-03 at 15:41, Timothy Legge wrote:
        > Hi
        >
        >
        >
        > I have a web service that I connect to as follows and dump the results
        > to the screen. The issue is that the data received from the web service
        > includes the same XML tag multiple times in the XML. However I do not
        > seem to be able to access that multiple iterations of that tag:
        >
        >
        >
        > I am not a Perl expert (or even a novice really) this is a learning
        > exercise. I am just trying to figure out whether this is an issue with
        > the use of the WDSL in SOAP::Lite, the way DUMPER outputs nested data
        > etc...
        >
        >
        >
        > The perl script, correct Web Service response and the SOAP:Lite data for
        > the response are below.
        >
        >
        >
        > Any ideas?
        >
        >
        >
        > =======================
        >
        > #!/usr/bin/perl
        >
        >
        >
        > use strict;
        >
        > use diagnostics;
        >
        > use warnings;
        >
        >
        >
        > use Data::Dumper;
        >
        >
        >
        > use SOAP::Lite;
        >
        > my $source = "sourcename";
        >
        > my $destination = "destinationname";
        >
        > my $systemmode = "Development";
        >
        >
        >
        > my $wsdl = "http://servername/beti/beti.asmx?WSDL";
        >
        > my $query = SOAP::Lite->service($wsdl);
        >
        >
        >
        > my $results = $query->GetOfficialStuff(
        >
        > $source,
        >
        > $destination,
        >
        > $systemmode);
        >
        >
        >
        > print Dumper($results);
        >
        > ==============================
        >
        > That web service returns an XML doc that looks like:
        >
        >
        >
        > <?xml version="1.0" encoding="utf-8"?>
        >
        > <GDEnvelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        > xmlns="http://domain.com/">
        >
        > <Header>
        >
        > <Source>sourcename</Source>
        >
        > <Destination>destinationname</Destination>
        >
        > <SystemMode>Development</SystemMode>
        >
        > <Err>
        >
        > <ErrorCode>0</ErrorCode>
        >
        > </Err>
        >
        > </Header>
        >
        > <GDs>
        >
        > <GD>
        >
        > <G>GName1</G>
        >
        > <Num>103</Num>
        >
        > <Day>0</Day>
        >
        > <LastDay>true</LastDay>
        >
        > </GD>
        >
        > <GD>
        >
        > <G>GName2</G>
        >
        > <Num>616</Num>
        >
        > <Day>0</Day>
        >
        > <LastDay>true</LastDay>
        >
        > </GD>
        >
        > </GDs>
        >
        > </GDEnvelope>
        >
        > =================================
        >
        > The result of the Dumper command is:
        >
        >
        >
        > $VAR1 = {
        >
        > 'GDs' => {
        >
        > 'GD' => {
        >
        > 'Num' => '616',
        >
        > 'Day' => '0',
        >
        > 'LastDay' => 'true',
        >
        > 'G' => 'GName2'
        >
        > }
        >
        > },
        >
        > 'Header' => {
        >
        > 'SystemMode' => 'Development',
        >
        > 'Destination' => 'sourcename',
        >
        > 'Source' => 'destinationname',
        >
        > 'Err' => {
        >
        > 'ErrorCode' => '0'
        >
        > }
        >
        > }
        >
        > };
        >
        >
        >
        >
        >
        > Tim
        >
        >
        > **********************************************************************
        > This E-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary, confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender and erase this E-mail message immediately.
        >
        > Le present message electronique (y compris les pieces qui y sont annexees, le cas echeant) s'addresse au destinataire indique et peut contenir des renseignements de caractere prive ou confidentiel. Si vous n'etes pas le destinataire de ce document, nous vous signalons qu'il est strictement interdit de le diffuser, de le distribuer ou de le reproduire. Si ce message vous a ete transmis par erreur, veuillez en informer l'expediteur et le supprimer immediatement.
        >
      • wmorgenstern@twmi.rr.com
        Try this code #!/opt/bin/perl use strict; use diagnostics; use warnings; use Data::Dumper; use SOAP::Lite; my $source = sourcename ; my $destination =
        Message 3 of 3 , May 4 4:58 AM
        • 0 Attachment
          Try this code

          #!/opt/bin/perl
          use strict;
          use diagnostics;
          use warnings;
          use Data::Dumper;
          use SOAP::Lite;

          my $source = "sourcename";
          my $destination = "destinationname";
          my $systemmode = "Development";

          my $wsdl = "http://servername/beti/beti.asmx?WSDL";
          my $query = SOAP::Lite->service($wsdl);
          my $method = SOAP::Data->name('GetOfficialStuff');
          my @params;
          push (@params, $source);
          push (@params, $destination);
          push (@params, $systemmode);
          my $som = $query->call($method => @params);

          for my $t ($som->valueof('//GDs/GD/*')) {
          print "G: " . $t->{G};
          print "Num: " . $t->{Num};
          print "Day: " . $t->{Day};
          print "LastDay: " . $t->{LastDay};
          }
        Your message has been successfully submitted and would be delivered to recipients shortly.