Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

XML module conflicts

by cLive ;-) (Prior)
on Mar 07, 2007 at 18:12 UTC ( [id://603660]=perlquestion: print w/replies, xml ) Need Help??

cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

This is more of a FYI than a question, but anyway...

I just spent the best part of a couple of hours trying to work out why this worked:

use strict; use warnings; use XML::Simple; my $x = XMLin('./test.xml');

yet this didn't

use strict; use warnings; use XML::Simple; use POE::Component::Jabber::XMPP; my $x = XMLin('./test.xml');

Turns out one the Jabber module loads POE::Filter::XML, which in turn loads XML::SAX

When this happens, XML::Simple defaults to the SAX parser, screwing up filename arguments.

The solution is to add:

$XML::Simple::PREFERRED_PARSER = 'XML::Parser';

to the script, but that feels clutzy.

I'm pondering on whether there's a better approach for the XML::Simple module, and would welcome input before I send an email to the module's owner. It doesn't seem right to me that a module's behaviour would change just by loading another module. Or am I just not being lazy enough? ;-) Thoughts?

Replies are listed 'Best First'.
Re: XML module conflicts
by runrig (Abbot) on Mar 07, 2007 at 18:43 UTC
    According to the docs, it seems like XML::SAX should have been loaded even in the first case (you might investigate and maybe mention that to the author). What concerns me more though is XML::SAX "screwing up filename arguments." Is that a bug in XML::SAX or one of the SAX parsers?
      Well, when sending a filename argument, I get this error: The only thing I know how to parse is a string. You have to fetch the data for me yourself. at /usr/local/lib/perl5/site_perl/5.8.8/XML/Simple.pm line 290 Hmmmm.
        What version of XML::Simple? Line 290 in the latest version (2.16) is just my ($tree);.
Re: XML module conflicts
by grantm (Parson) on Mar 10, 2007 at 03:45 UTC

    Your workaround seems reasonable.

    The underlying problem is that the XML::SAX::Expat::Incremental module doesn't implement the full SAX API. That being the case, it really would be best if POE::Filter::XML didn't force it to be the default SAX parser.

    I've submitted a patch which modifies POE::Filter::XML to directly instantiate the parser class it needs rather than using the ParserFactory.

Re: XML module conflicts
by runrig (Abbot) on Mar 08, 2007 at 18:29 UTC
    The problem is that the modules are fighting over the "preferred" SAX parser. XML::Simple has this line:
    $XML::SAX::ParserPackage = $preferred_parser if($preferred_parser);
    which means that it doesn't set the preferred parser unless you specify it, and falls back to whatever default it finds in ParserDetails.ini. Or it would fall back, except that POE::Filter::XML (used by the POE Jabber module) has this:
    $XML::SAX::ParserPackage = "XML::SAX::Expat::Incremental";
    It's the XML::SAX::Expat::Incremental throwing the error, because it will only parse strings. I don't know why the XML::SAX::ParserPackage has to be a package variable and can't be set per instance of XML::SAX (or maybe it can, I don't know), or if 'incremental' can be used as some sort of feature for the ParserDetails.ini file (for POE::XML::Filter to use), or maybe XML::Simple should undef the ParserPackage variable (which may screw up POE::Filter::XML since it sets ParserPackage upon module load...maybe POE::Filter::XML should only set it when it needs a SAX parser object). Anyway...your workaround seems the best for your problem for now, but I'm not sure what the best solution should be (they're not my modules, and I don't have the tuits :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-25 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found