http://www.perlmonks.org?node_id=721657


in reply to SOAP::Lite - Attribute in array

http://search.cpan.org/~mkutter/SOAP-Lite-0.710.08/lib/SOAP/SOM.pod#ACCESSING_ATTRIBUTE_VALUES
http://search.cpan.org/~mkutter/SOAP-Lite-0.710.08/lib/SOAP/SOM.pod#ITERATING_OVER_AN_ARRAY

Replies are listed 'Best First'.
Re^2: SOAP::Lite - Attribute in array
by DreamT (Pilgrim) on Nov 05, 2008 at 14:45 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
        Note that the first regex in the loop
        for($response_xml){ s/^s*//; s/\s*$//; }
        should be
        s/^\s*//;
        Or better yet, both regexes should perhaps be
        s/^\s+//; s/\s+$//;
        since there is little point in replacing zero whitespace with nothing.
        Thank you, you saved my day:-)
        (It worked after changing
        for my $t ($d->valueof('//get_ManufacturerListResult/Manufacturers/Man +ufacturer' ) )
        to
        for my $t ($d->dataof('//get_ManufacturerListResult/Manufacturers/Manu +facturer' ) )
        )