Skip Menu |

This queue is for tickets about the XML-Simple CPAN distribution.

Report information
The Basics
Id: 5185
Status: resolved
Priority: 0/
Queue: XML-Simple

People
Owner: Nobody in particular
Requestors: pdenis [...] fotango.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: XML::SAX as preferred parser
With perl 5.8.0 on Linux RH9, if I type: perl -e 'use XML::Simple; use Data::Dumper; $XML::Simple::PREFERRED_PARSER = 'XML::SAX' ; $xml = q{<?xml version="1.0" encoding="ISO-8859-1"?><opt><action>actiontest</action><params><foo>bar</foo></params></opt>}; print Dumper(XMLin($xml, keyattr => [], suppressempty => undef));' I obtain: Can't locate object method "new" via package "XML::SAX" at /usr/lib/perl5/site_perl/5.8.0/XML/SAX/ParserFactory.pm line 43. Regards
Hi Pierre Thanks for the report. The $XML::Simple::PREFERRED_PARSER variable is used to select a parser module. XML::SAX is not a parser module, hence the error. Available SAX parser modules include: XML::SAX::PurePerl, XML::SAX::Expat, XML::LibXML::SAX. If you use one of these in your code, it works: perl -e 'use XML::Simple; use Data::Dumper; $XML::Simple::PREFERRED_PARSER = 'XML::SAX::Expat'; $xml = q{<?xml version="1.0" encoding="ISO-8859-1"?><opt><action>actiontest</action><params><foo>bar</foo></params></opt>}; print Dumper(XMLin($xml, keyattr => [], suppressempty => undef));' If you are trying to have XML::Simple use the default SAX parser then there is no need to set the global - that's the default behaviour. You only need to set the variable if you wish to use a specific SAX parser or if you want to use XML::Parser instead of SAX. The other use of the variable is to override the default parser set in the 'XML_SIMPLE_PREFERRED_PARSER' environment variable. Setting $XML::Simple::PREFERRED_PARSER = '' will force the default behaviour of using a SAX parser if one is available. Regards Grant
Hi Grant, Sorry my mistake. This report was following some XML::Simple weirdness I was investigating. Essentially, on one box, I can't have Attribute::Handlers and XML::Simple loaded at the same time, if the box also has XML::LibXML::SAX installed. If I then specify $XML::Simple::PREFERRED_PARSER = 'XML::Parser', it works. If I don't use Attrinute::Handlers, it works... perl -e 'use Attribute::Handlers; use XML::Simple; $xml = q{<?xml version="1.0" encoding="ISO-8859-1"?><opt><action>actiontest</action><params><foo>bar</foo></params></opt>}; $hash = XMLin($xml, keyattr => [], suppressempty => undef);' displays the following error message: Can't locate object method 'XML::Simple::xml_decl' via package 'XML::Simple' at /home/pierre/dev/Fotango/Build/build/lib/perl5/site_perl/5.8.0/XML/SAX/Base.pm line 418 at /home/pierre/dev/Fotango/Build/build/lib/perl5/site_perl/5.8.0/i686-linux/XML/LibXML/SAX.pm line 63 Regards Pierre