in reply to XML parsing
#!/usr/bin/perl # use module use strict; use warnings; use XML::Simple; use Data::Dumper; # create object my $xml = new XML::Simple (KeyAttr=>[], ForceArray => ['function']); # IMPORTANT ^^^^^^^^^^ # read XML file my $data = $xml->XMLin("hosts.xml"); my $e = $data->{'host'}; print "Name: ", $e->{name}, "\n"; # IMPORTANT: Use a loop to process all the possible # functions, instead of just one. foreach my $fct ( @{$e->{'function'}} ){ print "Function: ", $fct, "\n"; }
Please use strict and warnings int he future, as it would have alerted you to the problems in your code instead of silently giving you no output.<allHosts> <host name="jimmy"> <function>web</function> <function>dns</function> <location>miami</location> </host> </allHosts>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML parsing
by Anonymous Monk on May 09, 2005 at 23:29 UTC | |
by crashtest (Curate) on May 10, 2005 at 03:17 UTC |