Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: SOAP::Lite - Attribute in array

by Anonymous Monk
on Nov 05, 2008 at 14:47 UTC ( [id://721669]=note: print w/replies, xml ) Need Help??


in reply to Re^2: SOAP::Lite - Attribute in array
in thread SOAP::Lite - Attribute in array

#!/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

Replies are listed 'Best First'.
Re^4: SOAP::Lite - Attribute in array
by AnomalousMonk (Archbishop) on Nov 05, 2008 at 15:09 UTC
    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.
      Thats funny, nothing replaced with nothing changes nothing :)

      Thanks

Re^4: SOAP::Lite - Attribute in array
by DreamT (Pilgrim) on Nov 05, 2008 at 15:04 UTC
    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' ) )
    )
      If my code didn't work as-is for you (as it did for me), upgrade SOAP::Lite

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-16 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found