Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: XML::Simple doesn't work

by PodMaster (Abbot)
on Nov 28, 2005 at 05:30 UTC ( #512096=note: print w/replies, xml ) Need Help??

in reply to XML::Simple doesn't work
The problem in this case is a bug in the XML::SAX::RTF installer, which registers itself in ...lib.../XML/SAX/ParserDetails.ini. This ini file is used to determine the default SAX parser and since XML::SAX::RTF was installed most recently, it is the default. Unfortunately, XML::SAX::RTF is not an XML parser (despite generating SAX events) so it should be removed from the ParserDetails.ini file.
Searching is essential.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^2: XML::Simple doesn't work
by jeanluca (Deacon) on Nov 28, 2005 at 20:56 UTC
    Yes that did work, I just emptied this file!!
    But I'm still confused why the following code is not working

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

    And here is a snippet of my xml file
    <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description> two of our famous Belgian Waffles with plenty of real maple syru +p </description> <calories>650</calories> </food> ..... </breakfast_menu>
    I thought XML::Simple was simple :(

      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://512096]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2017-03-23 21:12 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (294 votes). Check out past polls.