Operating System - Linux
1752815 Members
6224 Online
108789 Solutions
New Discussion юеВ

Re: Parsing XML with Perl - Which module

 
SOLVED
Go to solution
Daavid Turnbull
Frequent Advisor

Parsing XML with Perl - Which module

You will have to excuse me on this post as my knowledge and experience on CPan modules is a bit hit and miss.

I have some fairly uncomplicated XML I wish to extract from fields from.

If I can possibly avoid doing so I would like to avoid having to install extra modules on the clients server.

Surfing the CPan modules XML::Parser showed promise but this line:

use XML::Parser;

produces this error:
_____________

Can't locate XML/Parser.pm in @INC (@INC contains: /opt/aue/bin /opt/aue/lib /opt/perl5/lib/5.00503/PA-RISC2.0 /opt/perl5/lib/5.00503 /opt/perl5/lib/site_perl/5.005/PA-
RISC2.0 /opt/perl5/lib/site_perl/5.005 .) at ./t.pl line 12.
BEGIN failed--compilation aborted at ./t.pl line 12.
_____________

However this module is installed in some places:
__________

-r--r--r-- 1 bin bin 29402 Jun 21 2001 /opt/perl/lib/site_perl/5.6.1/PA-RISC1.1-thread-multi/XML/Parser.pm
-r--r--r-- 1 bin bin 23398 Jun 21 2001 /opt/perl/lib/site_perl/5.6.1/XML/XPath/Parser.pm
-r-xr-xr-x 1 bin bin 29402 Nov 8 2000 /opt/perl5.005_03/lib/5.00503/PA-RISC1.1/XML/Parser.pm
__________

My Question: Given that this module is installed is there are good reason why it is not installed for PA-RISC2.0? Is there some other module I should be using instead?
Behold the turtle for he makes not progress unless he pokes his head out.
7 REPLIES 7
Muthukumar_5
Honored Contributor

Re: Parsing XML with Perl - Which module

Module has to be in @INC path only. Try to put XML/Parser.pm into /opt/aue/bin or anyother directories in @INC. Or else, include /opt/perl/lib/site_perl/5.6.1/PA-RISC1.1-thread-multi/ directory into @INC directory.

hth.
Easy to suggest when don't know about the problem!
Daavid Turnbull
Frequent Advisor

Re: Parsing XML with Perl - Which module

My gut feeling is that there has to be more to this one than that. I picked the most likely looking candidate and put in a sym link:
____________
Can't locate loadable object for module XML::Parser::Expat in @INC (@INC contains: /opt/aue/bin /opt/aue/lib /opt/perl5/lib/5.00503/PA-RISC2.0 /opt/perl5/lib/5.00503 /o
pt/perl5/lib/site_perl/5.005/PA-RISC2.0 /opt/perl5/lib/site_perl/5.005 .) at /opt/aue/lib/XML/Parser.pm line 15
BEGIN failed--compilation aborted at /opt/aue/lib/XML/Parser.pm line 27.
BEGIN failed--compilation aborted at ./t.pl line 12.
Behold the turtle for he makes not progress unless he pokes his head out.
Ralph Grothe
Honored Contributor
Solution

Re: Parsing XML with Perl - Which module

Hi Daavid,

as XML lends itself to being parsed through Perl, as you can imagine, there is an abundance of Perl modules available for this purpose.
So it could be difficult to decide which one to use, and it depends on the XML source you need to parse, and on what you intend to achieve.
Most XML parsers fall into two categories.
Those that parse an XML document treating it as a tree, and those which are event based
(mind you there's even a SAX implementation for Perl).
However, some also are very versatile and allow both.
There are also pure Perl modules that don't require some extra C libraries, and of course the latter.
If your parsing is simple and if you don't have to parse huge chunks of XML I would suggest XML::Simple, which doesn't require the additional installation of XML libraries.
See
http://search.cpan.org/~grantm/XML-Simple-2.14/lib/XML/Simple.pm
for details.
However, be warned that XML::Simple can have a severe time penalty (especially if your XML is vast).
Afaik, it's also not suited for XML validation against a DTD or Schema (or RelaxNG), but merely well-formedness.
If the performance is prohibitive I'd suggest you go for XML::Parser which is based on one of the oldest XML parsers going back to an implimantation of Perl inventor Larry Wall himself.
http://search.cpan.org/~msergeant/XML-Parser-2.34/Parser.pm
Thus XML::Parser possibly lacks the latest of XML specification adherence.
I'm not sure if XML::Parser would install without libexpat, but I fear not.
So you as well would need to install the C library Expat which the module has to be linked against.
http://expat.sourceforge.net/
Because XML::Parser makes use of libexpat it's really rocking fast compared to XML::Simple.
The coding also differs significantly from XML::Simple as you would have to define callback functions for XML elements you need to catch.
As anside, many newer and more specialized XML Perl modules are based on XML::Simple.
Therefore it cannot hurt to have it installed.
Have you made sure that you installed the prerequisite libexpat?
Another nifty module is XML::XPath which I think also requires XML::Parser (thus also makes use of libexpat and is equally fast)
http://search.cpan.org/~msergeant/XML-XPath-1.13/XPath.pm
It builds on the XPath specification and implements the XPath functions as Perl methods.
It's especially easy to use for people used to Unix directory paths, which can be thought of as an analogy.
Then there's another big contender XML::libXML
http://search.cpan.org/~phish/XML-LibXML-1.58/LibXML.pod
which requires the Gnome libxml2
http://xmlsoft.org/
With it you can adhere fully to XML specification as it implements the Document Object Module (DOM) as well as the Simple API to XML (SAX) which is heavily used in the Java community.
I think these are the most prominent Perl modules if you need anything to do XML.
But there are dozens of others which maybe even better serve your purpose.
I would suggest you browse through CPAN and have a look at the POD of the other modules.



Madness, thy name is system administration
H.Merijn Brand (procura
Honored Contributor

Re: Parsing XML with Perl - Which module

1. You are using perl-5.005_03 which is not particulary recent. Though it is stable, chances that you hit problems that will never be solved are increasing by the day, certainly when using XS modules like XML::Parse that depend on external libraries (libexpat)

2. Yes there is more:

lt09:/home/merijn 104 > find /pro/lib/perl5 | grep XML | grep -w -v -e SAX -e PROCURA -e Twig -e XPath
/pro/lib/perl5/site_perl/5.8.7/Pod/Simple/XMLOutStream.pm
/pro/lib/perl5/site_perl/5.8.7/Pod/Simple/DumpAsXML.pm
/pro/lib/perl5/site_perl/5.8.7/XML
/pro/lib/perl5/site_perl/5.8.7/XML/Parser
/pro/lib/perl5/site_perl/5.8.7/XML/Parser/Lite.pm
/pro/lib/perl5/site_perl/5.8.7/Apache/XMLRPC
/pro/lib/perl5/site_perl/5.8.7/Apache/XMLRPC/Lite.pm
/pro/lib/perl5/site_perl/5.8.7/XMLRPC
/pro/lib/perl5/site_perl/5.8.7/XMLRPC/Lite.pm
/pro/lib/perl5/site_perl/5.8.7/XMLRPC/Transport
/pro/lib/perl5/site_perl/5.8.7/XMLRPC/Transport/TCP.pm
/pro/lib/perl5/site_perl/5.8.7/XMLRPC/Transport/HTTP.pm
/pro/lib/perl5/site_perl/5.8.7/XMLRPC/Transport/POP3.pm
/pro/lib/perl5/site_perl/5.8.7/XMLRPC/Test.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Style
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Style/Debug.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Style/Objects.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Style/Stream.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Style/Subs.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Style/Tree.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/LWPExternEnt.pl
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Expat.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/README
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/x-euc-jp-jisx0221.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/x-sjis-unicode.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/euc-kr.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/Japanese_Encodings.msg
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/x-sjis-cp932.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/x-euc-jp-unicode.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/x-sjis-jisx0221.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/x-sjis-jdk117.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/big5.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/iso-8859-2.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/iso-8859-3.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/iso-8859-4.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/iso-8859-5.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/iso-8859-7.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/iso-8859-8.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/iso-8859-9.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/windows-1250.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser/Encodings/windows-1252.enc
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/XML/Parser.pm
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/auto/XML
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/auto/XML/Parser
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/auto/XML/Parser/Expat
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/auto/XML/Parser/Expat/Expat.bs
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/auto/XML/Parser/Expat/Expat.so
/pro/lib/perl5/site_perl/5.8.7/i686-linux-64int/auto/XML/Parser/.packlist
lt09:/home/merijn 105 >

I propose to upgrade :)

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Ralph Grothe
Honored Contributor

Re: Parsing XML with Perl - Which module

Yes, I forgot XML::Twig.
I also had a typo where I wrote that many other XML modules were "based on XML::Simple".
This of course is dead wrong and I meant XML::Parser.
Once you have a current Perl installed you should try to install your required XML modules via the CPAN module (or its successor, as procura would suggest).
The advantage of this is that it reminds you of all dependencies (which can be quite a few), and also tries to download and build them.

Madness, thy name is system administration
Daavid Turnbull
Frequent Advisor

Re: Parsing XML with Perl - Which module

These detailed responses have given me something to think about.

Upgrading to a more recent version of Perl does sound like the answer I was looking for. I will have to talk to the sys admin for these machines to see what can be done.

I will leave this thread open for a couple of days and assign points once I have digested the information and re read the posts a couple of times.
Behold the turtle for he makes not progress unless he pokes his head out.
Daavid Turnbull
Frequent Advisor

Re: Parsing XML with Perl - Which module

Thanks guys. Your input was what I needed.
Behold the turtle for he makes not progress unless he pokes his head out.