BaldPenguin has asked for the wisdom of the Perl Monks concerning the following question:

I have long thought that Simple Modules should only be used for simple tasks, and since I normally do way too much with my xml, I have stuck with XML::Twig and XML::LibXML for the majority of my XML work. However in the case of using XML for an application config, this is what XML::Simple excels at.

In writing a bot for a jabber server, I have come across an error that I have yet to figure out. I have no problems getting the xml to parse until I use the POE::Component::Jabber::Client::XMPP module. Once I use the module and run, I get the error The only thing I know how to parse is a string. You have to fetch the data for me yourself. at /usr/lib/perl5/vendor_perl/5.8.5/XML/Simple.pm line 287. Thinking that that meant I needed to read the file into a string first, I tried that, and got the same error.

Using this simple XML file:
<?xml version ="1.0"?> <config> <version>0.1</version> <application> <hostname>testme.com</hostname> <user>monk</user> <password>pass</password> </application> </config>
and this script:
use POE::Preprocessor; const XNode POE::Filter::XML::Node use strict; use warnings; use POE qw/ Component::Jabber::Client::XMPP Component::Jabber::Error / +; use POE::Filter::XML::Node; use POE::Filter::XML::NS qw/ :JABBER :IQ /; use List::Util qw/ shuffle /; use XML::Simple; my $config = XMLin('test.xml'); use Data::Dumper(); warn Data::Dumper::Dumper( $config ); exit(0);
I can repro the error. If I remove the 'Component::Jabber::Client::XMPP' part, the XML parses, but then my bot wouldn't work.

Has anyone run accross this and overcome the problem?

Also, I tried switching over to the Legacy module in place of the XMPP, and got the same error.

Don
WHITEPAGES.COM | INC
Everything I've learned in life can be summed up in a small perl script!

Replies are listed 'Best First'.
Re: Jabber XMPP and XML::Simple conflict
by bmann (Priest) on Aug 17, 2005 at 19:08 UTC
    XML::Simple uses a SAX parser by default, if available. I found that exact error message in XML::SAX::Expat::Incremental.

    Try setting PREFERRED_PARSER, ie:

    $XML::Simple::PREFERRED_PARSER = 'XML::Parser';
    to prevent XML::Simple from using SAX, see if that clears it up...
      That was the answer, thank you!

      Don
      WHITEPAGES.COM | INC
      Everything I've learned in life can be summed up in a small perl script!

        The most recent version of XML::SAX::Expat::Incremental does not register itself in XML/SAX/ParserDetails.ini. If you edit that file and remove the offending section then XML::Simple will work with SAX parsers too.