The trick here is not to use the SOAP::SOM->valueof method, but to use the SOAP::SOM->dataof method which returns a SOAP::Data object. A SOAP::Data object provides a much more accessible API to the various tid-bits buried in an XML element. So once you have your hands on the SOAP::Data object, you then need to call the SOAP::Data->attr() subroutine. Here is what the book says:
"Allows for the setting of arbitrary attributes on the data object. Keep in mind the requirement that any attributes not natively known to SOAP must be namespace-qualified. Also allows the setting of the object's value, if passed as a second argument to the method."
The book makes no mention of "getting" attributes, but it is easy. If you pass a HASH reference to the attr() subroutine than you are performing a set operation, if you pass a SCALAR reference than you are performing a lookup or get operation. So to fetch an attribute's value, your code will look like this:
$response = $client->c2f("100");
print "The attribute is: " . $response->dataof('//c2fResponse/convertedTemp')->attr->{'test'} . "\n";
Easy, shmeazy.
thanks for the response.
how would i access attributes in a situation like like this where the tags all have the same name?
Posted by: Paul Yuergens | June 20, 2003 at 02:44 PM
Is there a way to just accept an envelope of information from a non-perl server and read it with soap::lite on the recieving end with out responding? I've been looking through "Web Services with Perl" and can't seem to find any examples, could you help on this?
Posted by: Joe McTigue | April 24, 2007 at 06:23 AM
I'm new to CGI perl and SOAP::Lite and was wondering if anyone could offer some advice on the following code and also whether or not I'd need a client script or not since my application is only to recieve enveloped data and insert it into a data base with out responding to the sending server.
CGI code follows:
#!/usr/bin/perl -wT
######################################################################################
## Script Name: recieve_log.cgi ##
## Date Created: April 23, 2007 ##
## Author: Joseph P. McTigue ##
## Created for: ##
## ##
## Purpose: to accept envelope message from distributed servers and inserts ##
## recieved data into the BU_LOG table of the data base via the ##
## LogToBuLog package. ##
## Accepts: xml formated data envelopes. ##
######################################################################################
use strict;
use CGI ':standard', '-debug';
use lib '/path/to/module/lib';
use SOAP::Transport::HTTP;
my @values;
my @fieldname = ("loglevel","userid","application","message","pid",
"hostname","category","srcfile","line","stack");
my $fieldname = "";
my $valuestr = "";
######################################################################################
######## Get values from Envelope and concatenate into coma delemeted string #########
######################################################################################
my $som = SOAP::Lite
->uri(?) # I have no idea what the next two lines are for if
->proxy(?) # I'm just recieving an envelope from an random server
; # and not responding or sending anything back.
if ( $som->match(SOAP::SOM::envelope) ) {
$som->valueof('Body'); # should give access to body
my $x = 0;
for my $t ($som->valueof('//items')) {
push( @values, $t->{$fieldname[$x]} ); #captures values by xml tags/fieldnames.
$x++;
}
$valuestr = join( "|", @values );
} else {
print "No Body is Home... bad joke I know.\n";
}
if ( $som->fault ) {
die $som->fault->faultstring;
}
######################################################################################
######## Pass delimetedted values in value string to logging_to_BuLog module #########
######## to be parsed and inserted into the BU_LOG table in the DB. #########
######################################################################################
my $logbu = new LogToBuLog;
$results = $logbu->logging_to_BuLog( $valuestr );
if (! $results) {
print "FAILURE!\n\n";
} else {
print "POSSIBLE SUCCESS, check Toad to verify insert made it into DB...\n\n";
}
1;
Posted by: joe | April 24, 2007 at 11:14 AM