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

This issue turned out to be a bad LD_LIBRARY_PATH :-(

I'm trying to use XML::Simple to parse a VERY simple xml file. The code works when used with perl debug (perl -d), but when run standalone, it fails with

Can't locate object method "new" via package "XML::LibXML::SAX" at /cp +an/5.8.8-2006.03/lib/XML/SAX/ParserFactory.pm line 43.

As far as I can tell, I have the right modules etc, although a little old now. The code is very simple:

#!/perl/5.8.8/bin/perl use 5.8.8; use strict; use warnings; use lib qw( /cpan/5.8.8-2006.03/lib /cpan-extra/5.8.8-2006.07 ); use Data::Dumper; use XML::Simple; my $file = 'test.xml'; my $ref = XMLin($file) or die "Error reading build file ($file): $@"; print Dumper($ref); # -end-

Can anyone suggest my next course of action? I don't have to use Simple, but looking at how to parse something very simple:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <SA> <BUILD> <name>oracle</name> <version>2.4.7</version> <size>672K</size> <date>Thu Nov 8 13:07:18 EST 2007</date> <builder>me</builder> <os>RHEL 3</os> <server>labtest1</server> <command>d2tbuild.pl</command> </BUILD> <SVN> <url>https://svr/prod/Oracle/tags/REL_1.2.3_01</url> <rev>19858</rev> </SVN> </SA>
XML::Parser etc. seeams far to complex. I'm limited on what modules I can use. So most of the newer 'easy' type aren’t available to me.
-- David

Replies are listed 'Best First'.
Re: error from XML::Simple
by ikegami (Patriarch) on Feb 19, 2010 at 21:15 UTC

    XML::Simple relies on other XML parsers. It can use XML::Parser or one of many SAX parsers. XML::Simple is at its fastest when it uses XML::Parser, so you should install XML::Parser and set

    $XML::Simple::PREFERRED_PARSER = 'XML::Parser';
    to make sure XML::Simple will use it. Hopefully, that will also bypass the problem you have with XML::SAX.
Re: error from XML::Simple
by Khen1950fx (Canon) on Feb 19, 2010 at 21:56 UTC
    Here's an example of another way to do it:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use XML::Simple qw(:strict); my $file = <DATA>; my $ref = XMLin($file, KeyAttr => {item => 'firstname'}, ForceArray => [ 'item' ], ContentKey => '-content' ); print Dumper($ref); __DATA__ <opt> <person key="jsmith" firstname="Joe" lastname="Smith" /> <person key="tsmith" firstname="Tom" lastname="Smith" /> <person key="jbloggs" firstname="Joe" lastname="Bloggs" /> </opt>