Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://512433]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-03-21 02:13 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (263 votes). Check out past polls.