#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
my $xml_parser = XML::Simple->new();
for my $icon_link_xml (
'http://www.nws.noaa.gov/weather/images/fcicons/sct.jpg',
'',
'',
'http://www.nws.noaa.gov/weather/images/fcicons/sct.jpg',
) {
my $xml = <<"EOXML";
Conditions Icons
$icon_link_xml
http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg
EOXML
# print "$xml\n";
my $data = $xml_parser->XMLin($xml);
# print Dumper $data;
my $icon_link = $data->{'data'}{'parameters'}{'conditions-icon'}{'icon-link'};
print Dumper $icon_link;
# use the next entry, for example
my $idx = ref($icon_link->[0]) eq "HASH" ? 1 : 0;
my $weatherIconURL = $icon_link->[$idx];
# or skip entirely
#next if ref($icon_link->[0]) eq "HASH";
print "=> \$weatherIconURL: $weatherIconURL\n\n";
}
__END__
$VAR1 = [
'http://www.nws.noaa.gov/weather/images/fcicons/sct.jpg',
'http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg'
];
=> $weatherIconURL: http://www.nws.noaa.gov/weather/images/fcicons/sct.jpg
$VAR1 = [
{
'xsi:nil' => 'true'
},
'http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg'
];
=> $weatherIconURL: http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg
$VAR1 = [
{
'foo' => 'bar'
},
'http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg'
];
=> $weatherIconURL: http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg
$VAR1 = [
{
'content' => 'http://www.nws.noaa.gov/weather/images/fcicons/sct.jpg',
'foo' => 'bar'
},
'http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg'
];
=> $weatherIconURL: http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg
####
$weatherIconURL = $data->{'data'}{'parameters'}{'conditions-icon'}{'icon-link'}[0]{content};