Richard Lee wrote:
Not sure why I get this..
As xml file is very very simple one(I even tried to put different
encoding as well).
Below is all necessary information.
[EMAIL PROTECTED] script]# uname -a
Linux xmen 2.6.25.14-108.fc9.i686 #1 SMP Mon Aug 4 14:08:11 EDT 2008
i686 i686 i386 GNU/Linux
[EMAIL PROTECTED] script]# cat /etc/issue
Fedora release 9 (Sulphur)
Kernel \r on an \m (\l)
fortune | cowsay
[EMAIL PROTECTED] script]# ./weather.pl weather.xml
not well-formed (invalid token) at line 3, column 26, byte 60 at
/usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi/XML/Parser.pm
line 187
<?xml version='1.0' ?>
<FORECAST>
<OUTLOOK>Partly Cloudy<\OUTLOOK>
<TEMPERATURE TYPE="MAX" DEGREES="C">12</TEMPERATURE>
<!-- <TEMPERATURE TYPE="MIN" DEGREES="C">6</TEMPERAURE> -->
</FORECAST>
use strict;
use warnings;
use XML::Parser;
my %forecast;
my @curr;
my $type;
my $p1 = new XML::Parser(Style => 'Stream');
my $yahoo = shift;
$p1->parsefile($yahoo);
print "Outlook: $forecast{outlook}\n";
foreach (keys %forecast) {
next if /outlook/;
print "$_: $forecast{$_}->{val} $forecast{$_}->{deg}\n";
}
sub StartTag {
my ($p, $tag) = @_;
push @curr, $tag;
if ($tag eq 'TEMPERATURE') {
$type = $_{TYPE};
$forecast{$type}->{deg} = $_{DEGREES};
}
}
sub EndTag {
pop @curr;
}
sub Text {
my ($p) = shift;
return unless /\S/;
s/^\s+//;
s/^\s+$//;
if ($curr[-1] eq 'OUTLOOK') {
$forecast{outlook} .= $_;
} elsif ( $curr[-1] eq 'TEMPERATURE' ) {
$forecast{$type}->{val} = $_;
}
}
sorry, just saw the typo on xml file
<?xml version='1.0' ?>
<FORECAST>
<OUTLOOK>Partly Cloudy<\OUTLOOK> <--- typo here
<TEMPERATURE TYPE="MAX" DEGREES="C">12</TEMPERATURE>
<!-- <TEMPERATURE TYPE="MIN" DEGREES="C">6</TEMPERAURE> -->
</FORECAST>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/