in reply to Problem Parsing XML with Perl

A URI can't be a HASH reference at /System/Library/Perl/Extras/5.8.8/LWP/Simple.pm line 113

Is there some way that I can ignore <icon-link xsi:nil="true"/>

The error message points you to a possible way around the problem: test if ->[0] is a hashref, and if so, skip to the next entry, or skip that case entirely, or whatever you'd consider an appropriate workaround in case of missing data.

The thing is that XML::Simple is creating an extra hashref as soon as the XML tag has an attribute (such as <icon-link foo="bar" ...).  You can always use Data::Dumper to figure out such things yourself. Consider the following:

#!/usr/bin/perl use XML::Simple; use Data::Dumper; my $xml_parser = XML::Simple->new(); for my $icon_link_xml ( '<icon-link>http://www.nws.noaa.gov/weather/images/fcicons/sct.jpg +</icon-link>', '<icon-link xsi:nil="true"/>', '<icon-link foo="bar"/>', '<icon-link foo="bar">http://www.nws.noaa.gov/weather/images/fcico +ns/sct.jpg</icon-link>', ) { my $xml = <<"EOXML"; <?xml version='1.0' ?> <dwml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <data> <parameters> <conditions-icon> <name>Conditions Icons</name> $icon_link_xml <icon-link>http://www.nws.noaa.gov/weather/images/fcicons/nra3 +0.jpg</icon-link> </conditions-icon> </parameters> </data> </dwml> 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/nra +30.jpg $VAR1 = [ { 'foo' => 'bar' }, 'http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg' ]; => $weatherIconURL: http://www.nws.noaa.gov/weather/images/fcicons/nra +30.jpg $VAR1 = [ { 'content' => 'http://www.nws.noaa.gov/weather/images/fcico +ns/sct.jpg', 'foo' => 'bar' }, 'http://www.nws.noaa.gov/weather/images/fcicons/nra30.jpg' ]; => $weatherIconURL: http://www.nws.noaa.gov/weather/images/fcicons/nra +30.jpg

Alternatively, you could set ForceContent => 1, and then use

$weatherIconURL = $data->{'data'}{'parameters'}{'conditions-icon'} +{'icon-link'}[0]{content};

In that case, the URL would simply be undefined (for <icon-link xsi:nil="true"/>) — which you'd have to check for as well, of course, to prevent further steps from erroring out when trying to fetch it...