Home > Archive > PERL Beginners > February 2005 > Issues dealing with XML::Simple output
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Issues dealing with XML::Simple output
|
|
| Chris Woodfield 2005-02-21, 8:56 pm |
| Hello,
I'm taking my first stab at dealing with parsed XML output, using the
XML::Simple module. My XML is a list of names associated with city codes
(to determine who gets notified of alarms in each site), but due to
what's most likley an obvious newbie error, I'm getting errors reading
the output.
The error I get is as follows:
Pseudo-hashes are deprecated at ./parse_xml_nokeyattr.pl line 22,
<STDIN> line 1.
Argument "\x{41}\x{54}..." isn't numeric in hash element at
../parse_xml_nokeyattr.pl line 22, <STDIN> line 1.
Bad index while coercing array into hash at ./parse_xml_nokeyattr.pl
line 22, <STDIN> line 1.
Can someone point out what I'm doing wrong?
Here's the script:
#!/usr/bin/perl -w
use strict;
use XML::Simple qw(:strict);
use Data::Dumper;
#use diagnostics;
# This is a test of the XML::Simple module along with Data::Dumper.
my $xmlFile="notifyi_simple.xml";
# create object
my $xml = new XML::Simple(ForceArray => 1, KeyAttr => []);
# parse XML using object method XMLin
my $ref = $xml->XMLin($xmlFile);
print "What city? ";
chomp(my $cityName = <STDIN> );
#take city output and return list of corresponding mailto elements
foreach (@{$ref->{site}->{name}->{$cityName}->{mailto}})
{
print $_, "\n";
}
And here's the XML:
<xml version="1.0">
<site name="ATL">
<mailto>mike</mailto>
<mailto>jeff</mailto>
<mailto>noc</mailto>
</site>
<site name="WDC">
<mailto>chris</mailto>
<mailto>noc</mailto>
</site>
<site name="SEA">
<mailto>jeff</mailto>
<mailto>noc</mailto>
</site>
</xml>
Thanks,
-Chris
| |
| Chris Woodfield 2005-02-21, 8:56 pm |
| Chris Woodfield wrote:
> Hello,
>
> I'm taking my first stab at dealing with parsed XML output, using the
> XML::Simple module. My XML is a list of names associated with city codes
> (to determine who gets notified of alarms in each site), but due to
> what's most likley an obvious newbie error, I'm getting errors reading
> the output.
>
> The error I get is as follows:
>
> Pseudo-hashes are deprecated at ./parse_xml_nokeyattr.pl line 22,
> <STDIN> line 1.
> Argument "\x{41}\x{54}..." isn't numeric in hash element at
> ./parse_xml_nokeyattr.pl line 22, <STDIN> line 1.
> Bad index while coercing array into hash at ./parse_xml_nokeyattr.pl
> line 22, <STDIN> line 1.
>
> Can someone point out what I'm doing wrong?
>
> Here's the script:
>
> #!/usr/bin/perl -w
>
> use strict;
> use XML::Simple qw(:strict);
> use Data::Dumper;
> #use diagnostics;
>
> # This is a test of the XML::Simple module along with Data::Dumper.
>
> my $xmlFile="notifyi_simple.xml";
>
> # create object
> my $xml = new XML::Simple(ForceArray => 1, KeyAttr => []);
>
> # parse XML using object method XMLin
> my $ref = $xml->XMLin($xmlFile);
>
> print "What city? ";
> chomp(my $cityName = <STDIN> );
>
> #take city output and return list of corresponding mailto elements
> foreach (@{$ref->{site}->{name}->{$cityName}->{mailto}})
> {
> print $_, "\n";
> }
>
> And here's the XML:
>
> <xml version="1.0">
>
> <site name="ATL">
> <mailto>mike</mailto>
> <mailto>jeff</mailto>
> <mailto>noc</mailto>
> </site>
>
> <site name="WDC">
> <mailto>chris</mailto>
> <mailto>noc</mailto>
> </site>
>
> <site name="SEA">
> <mailto>jeff</mailto>
> <mailto>noc</mailto>
> </site>
>
> </xml>
>
> Thanks,
>
> -Chris
Also, here's the Data::Dumper output:
$VAR1 = {
'site' => [
{
'mailto' => [
'mike',
'jeff',
'noc'
],
'name' => 'ATL'
},
{
'mailto' => [
'chris',
'noc'
],
'name' => 'WDC'
},
{
'mailto' => [
'jeff',
'noc'
],
'name' => 'SEA'
}
],
'version' => '1.0'
};
|
|
|
|
|