Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

XML::Simple doesn't work

by jeanluca (Deacon)
on Nov 27, 2005 at 19:56 UTC ( #512040=perlquestion: print w/replies, xml ) Need Help??
jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I just tried to use XML::Simple, but when the following line executes my $doc = $xs1->XMLin($file) The program stops with the following message:
No _parse_* routine defined on this driver (If it is a filter, remembe +r to set the Parent property. If you call the parse() method, make su +re to set a Source. You may want to call parse_uri, parse_string or p +arse_file instead.) [XML::SAX::RTF=HASH(0x815133c)] at /usr/lib/perl5 +/site_perl/5.8.6/XML/SAX/ line 2308.
Any suggestion what I did/do wrong!!?

Thanks in advance

Replies are listed 'Best First'.
Re: XML::Simple doesn't work
by GrandFather (Sage) on Nov 27, 2005 at 20:07 UTC

    When I tried the following code I received no errors. Perhaps you need to tell us a little more about your problem? Flesh the code below out until you can reproduce the error that you are seeing, or tell us more about your context if the code below generates your error.

    use strict; use warnings; use XML::Simple; my $xs1 = new XML::Simple (); my $doc = $xs1->XMLin (<DATA>) __DATA__ <end/>

    For future reference you might want to take a look at this and this.

    DWIM is Perl's answer to Gödel
Re: XML::Simple doesn't work
by thor (Priest) on Nov 27, 2005 at 20:05 UTC
    Could you try posting a small program that exhibits the problem that you're seeing? Assuming that $xsl was created like my $xsl = XML::Simple->new(), then what you did should work...


    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

Re: XML::Simple doesn't work
by Aristotle (Chancellor) on Nov 27, 2005 at 20:42 UTC

    Without a snippet of code that shows what you did and at least one short sample of the input that causes this error, noone is going to be able to do anything but guess. Please do yourself a favour and read How (Not) To Ask A Question (see also the recent I know what I mean. Why don't you?).

    Makeshifts last the longest.

Re: XML::Simple doesn't work
by PodMaster (Abbot) on Nov 28, 2005 at 05:30 UTC
    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.

      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: perlquestion [id://512040]
Approved by gjb
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2018-06-23 00:45 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.