Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by grantm (Parson)
on Nov 28, 2005 at 23:34 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found