Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: SOAP::Lite - Attribute in array

by Anonymous Monk
on Nov 05, 2008 at 14:20 UTC ( #721657=note: print w/ replies, xml ) Need Help??

Comment on Re: SOAP::Lite - Attribute in array
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
        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' ) )
        )
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://721657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-12-26 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls