How to use XML::Simple when XML is in an object?
I have this code
#!/usr/bin/perl -w
use开发者_如何学JAVA strict;
use URI;
use LWP::UserAgent;
use Data::Dumper;
use XML::Simple;
my $DBVersion = '';
my $url = URI->new('https://example.com');
$url->query_form(
'sql' => 'select email,firstname from account for xml auto',
'DBVersion' => $DBVersion
);
my $response = LWP::UserAgent->new->get($url);
die "Error: ", $response->status_line unless $response->is_success;
print $response->content;
And now I would like to use XML::Simple
on $response->content
.
From can I see that they use
my $doc = $xs1->XMLin($file);
foreach my $key (keys (%{$doc->{species}})){
print $doc->{species}->{$key}->{'common-name'} . ' (' . $key . ') ';
print $doc->{species}->{$key}->{conservation}->final . "\n";
}
But my XML data in not in a file, but in an object created by the LWP module.
How can I parse that data with XML::Simple
?
XMLin()
can accept a string of XML as a parameter:
use XML::Simple;
my $ref = XMLin($response->content);
See perldoc XML::Simple for the details.
精彩评论