Hi all i am a newbie with perl, actually not even a newbie, i havent really started to learn perl, i do know php and various others but never touched perl. i have a perl script that downloads the weather from an xml and puts it into speech using festival. it recently stopped working and ive tracked the problem to them adding latin1 to the encoding="" in their xml. so xml::Simple and parser are complaining cause its in Latin1 and they dont know what that is. i figure just striping out LATIN1 would fix it since i am only using 0-9, a-z, and regular chars like comma, period, semi colon, no specials at all. this is the relevant code, xml, and error:
#!/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";
I believe that is the releavant parts the rest is similiar code... this is the relevant part of the xml:
<?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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.