DreamT has asked for the wisdom of the Perl Monks concerning the following question:

Hi! I'm working with a Perl webservice client using SOAP::Lite. The xml response template looks something like this:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" x +mlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schema +s.xmlsoap.org/soap/envelope/"> <soap:Body> <get_ManufacturerListResponse xmlns="http://webservice.isolda.se/S +tandard"> <get_ManufacturerListResult> <StatusID>int</StatusID> <StatusMessage>string</StatusMessage> <InputString>string</InputString> <Results>int</Results> <Generated>dateTime</Generated> <Manufacturers> <Manufacturer ManufacturerCode="HP" /> <Manufacturer ManufacturerCode="Lexmark" /> </Manufacturers> </get_ManufacturerListResult> </get_ManufacturerListResponse> </soap:Body> </soap:Envelope>
I am able to extract the values I want (StatusID etc), EXCEPT for the Manufacturer attribute "ManufacturerCode". (I'm using the following method to get the values
my $StatusID = $soapSvar->valueof('//get_ManufacturerListResult/Status +ID'); )
(And, I'm actually able to loop over all the 'Manufacturer' posts using
for my $t ($som->valueof('//get_ManufacturerListResult/Manufacturers/M +anufacturer')) { }
) BUT, in the loop above, i'm not able to "get" the manufacturerCode attribute ("HP", "Lexmark" etc.). How should I do it?
Regards, Jimmy

Replies are listed 'Best First'.
Re: SOAP::Lite - Attribute in array
by Anonymous Monk on Nov 05, 2008 at 14:20 UTC
      I've looked at the two links you posted, but I just don't know how to combine them:-)
      (I.e. how to reach the atttibute when I'm in the loop)
        #!/usr/bin/perl -- use strict; use warnings; my $response_xml = <<'__RESPONSE__'; <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" x +mlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schema +s.xmlsoap.org/soap/envelope/"> <soap:Body> <get_ManufacturerListResponse xmlns="http://webservice.isolda.se/S +tandard"> <get_ManufacturerListResult> <StatusID>int</StatusID> <StatusMessage>string</StatusMessage> <InputString>string</InputString> <Results>int</Results> <Generated>dateTime</Generated> <Manufacturers> <Manufacturer ManufacturerCode="HP" /> <Manufacturer ManufacturerCode="Lexmark" /> </Manufacturers> </get_ManufacturerListResult> </get_ManufacturerListResponse> </soap:Body> </soap:Envelope> __RESPONSE__ for($response_xml){ s/^s*//; s/\s*$//; } use XML::Simple; use Data::Dumper; $Data::Dumper::Indent=1; print Dumper( XMLin( $response_xml )), $/,'----',$/; use SOAP::Lite; my $d = SOAP::Custom::XML::Deserializer->deserialize( $response_xml ); print $d->valueof('/Envelope/Body'), $/,'----',$/; print 'statusid ', $d->valueof('//get_ManufacturerListResult/StatusID' +), $/,'----',$/; print $d->dataof('//get_ManufacturerListResult/Manufacturers/Manufactu +rer')->attr->{'ManufacturerCode'}; print $/,'----',$/; for my $t ($d->valueof('//get_ManufacturerListResult/Manufacturers/Man +ufacturer' ) ){ print $t->attr->{'ManufacturerCode'}; # print Dumper( $t ); } __END__ $VAR1 = { 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'soap:Body' => { 'get_ManufacturerListResponse' => { 'xmlns' => 'http://webservice.isolda.se/Standard', 'get_ManufacturerListResult' => { 'StatusID' => 'int', 'Manufacturers' => { 'Manufacturer' => [ { 'ManufacturerCode' => 'HP' }, { 'ManufacturerCode' => 'Lexmark' } ] }, 'InputString' => 'string', 'Results' => 'int', 'StatusMessage' => 'string', 'Generated' => 'dateTime' } } }, 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' }; ---- int ---- statusid int ---- HP ---- HPLexmark