Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: XML::Simple doesn't work

by grantm (Parson)
on Nov 28, 2005 at 23:34 UTC ( #512433=note: print w/ replies, xml ) Need Help??


in reply to Re^2: XML::Simple doesn't work
in thread XML::Simple doesn't work

But I'm still confused why the following code is not working

If you don't enable the KeepRoot option (and you generally don't want it enabled), then the outermost tags from your XML will not be in the resulting hashref. So here's a version that's probably closer to what you want:

#!/usr/bin/perl use XML::Simple ; my $xs1 = XML::Simple->new(); my $breakfast_menu = $xs1->XMLin("test.xml"); foreach my $key (keys (%$breakfast_menu)){ print "$key --> $breakfast_menu->{$key}->{name}\n" ; }

The fact that you're not specifying any options at all in you XMLin() call is a big red flag. This article gives some background on the basic options you ought to be using.

I thought XML::Simple was simple :(

Well, the single biggest shortcoming of XML::Simple is that it can't read your mind :-)

This article has some advice on using LibXML instead.


Comment on Re^3: XML::Simple doesn't work
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://512433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-09-19 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls