On 29 Mar 2007 at 12:39, Beginner wrote:

> Hi,
> 
> I might be in above my head here so bear with me if I am not making 
> sense.
> 
> I have to retrieve and extract an xml fragment from a REST server. I 
> have followed some examples from the "Web Services" book. I am able 
> to retrieve the data via LWP::UserAgent but I am baffled by the hash 
> ref that's returned. Data::Dumper prints it as this (excuse the 
> formatting) :
> 
> $VAR1 = bless( {
>                  '_protocol' => 'HTTP/1.1',
>                  '_content' => '<address id="1029">
>   <addressLine1>YORK</addressLine1>
>   <addressLine2>W1T 6RF</addressLine2>
>   <addressLine3></addressLine3>
>   <addressLine4></addressLine4>
>   <addressLine5></addressLine5>
>   <country id="227"/>
>   <postcode>W1T 6RF</postcode>
> </address>',
>                  '_rc' => 200,
>                  '_headers' => bless( {
>                                         'client-date' => 'Thu, 29 Mar 
> 2007 11:20:51 GMT',
>                                         'content-type' => 'text/xml',
>                                         'client-response-num' => 1,
>                                         'client-peer' => 
> '127.0.0.1:8182',
>                                         'content-length' => '256',
>                                         'server' => 'Restlet-
> Engine/1.0b14'
>                                       }, 'HTTP::Headers' ),
>                  '_msg' => 'The request has succeeded',
>                  '_request' => bless( {
>                                         '_content' => '',
>                                         '_uri' => bless( do{\(my $o = 
> 'http://localhost:8182/core/address/1029')}, 'URI::http' ),
>                                         '_headers' => bless( {
>                                                                'user-
> agent' => 'libwww-perl/5.803'
>                                                              }, 
> 'HTTP::Headers' ),
>                                         '_method' => 'GET'
>                                       }, 'HTTP::Request' )
>                }, 'HTTP::Response' );
> 
> 
> I am not sure who I am work with the data. The bless reference means 
> I have just stepped into the murky workd of OO perl. The data I am 
> after is the address xml fragment at the top.
> 
> Can anyone offer me any tips to get me started? How do I reference 
> the 'Object' at the top of the response? Is there a module that will 
> help 'deserialize' the response?


My mistake. The examples in the books show how to do that. Basically 
pass SOAP::Deserializer the content returned by LWP and it will do 
all the heavy lifting for you...phew.

so 

my $fragment = parse($res->content);
print $fragment->{'some_tag_value'}, "\n";

sub parse {
 use SOAP::Lite;
 return SOAP::Custom::XML::Deserializer->deserialize(shift)->root;
}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to