I believe that is the releavant parts the rest is similiar code... this is the relevant part of the xml:#!/usr/bin/perl use POSIX; use XML::Parser; use XML::Simple; use Data::Dumper; use LWP::Simple; #use Switch; my $url = "http://apple.accuweather.com/adcbin/apple/Apple_Weather_Dat +a.asp?zip$ my $file = get($url); $file =~ s/encoding="[^"] "//; my $xs1 = XML::Simple->new(); if(-e "/var/lib/asterisk/sounds/currentconditions.ulaw") { unlink("/var/lib/asterisk/sounds/currentconditions.ulaw"); } if(-e "/var/lib/asterisk/sounds/planets.ulaw") { unlink("/var/lib/asterisk/sounds/planets.ulaw"); } if(-e "/var/lib/asterisk/sounds/forecast.ulaw") { unlink("/var/lib/asterisk/sounds/forecast.ulaw"); } my $doc = $xs1->XMLin($file, ForceContent => 1); # this is the current conditions section my $city = $doc->{CurrentConditions}->{City}->{content}; $city =~ s/^\s*(.*?)\s*$/$1/; my $speech_text = "Current conditions for $city, "; print "City: " , $city , "\n";
<?xml version="1.0" encoding="LATIN1"?> <adc_Database> <WatchWarnAreas zone="NJZ008" county="NJC027"/> <GmtDiff DayLightSavings="0" > -5 </GmtDiff> <CurrentConditions> <City> Lake Hopatcong </City> <State> NJ </State>
i believe they added that latin1 part recently is why its not working :(
the error is:
Couldn't open encmap latin1.enc:
No such file or directory
at /usr/local/lib/perl/5.8.4/XML/Parser.pm line 187
UPDATE: i added
$file =~ s{encoding="LATIN1 "}{encoding=""};
which fixed the latin1.enc error but now i get the following error:
XML declaration not well-formed at line 1, column 30, byte 30 at /usr/local/lib/ perl/5.8.4/XML/ Parser.pm line 187
UPDATE 2:
I am happy to report i got this working by changing my code to:
$file =~ s{encoding="LATIN1 "}{encoding="utf-8"};
i guess it wanted utf-8 instead of blank encoding. thanks all.
In reply to XML and Latin1 issue by mike240se
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |