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

Hello,

today we use XML::Parser wrapped in an own package to work with xml files, which build a data structure of hashes and arrays. This works for simple xml files, but is not very convenient as well. therefore we think of using XPath in the future, the only question is with which library.

It seems there's mainly XML::XPath, which seems pretty old, and XML::LibXML, which needs binary parts. We work with Windows and Linux and with Windows it's sometimes even hard to get DBD::Pg and the needed or provided binary parts running properly.

Which library would you prefer today?

Replies are listed 'Best First'.
Re: preferred XPath library in perl
by choroba (Cardinal) on Aug 05, 2010 at 11:08 UTC
    We use XML::LibXML on both Linux and Windows with no major problems.
Re: preferred XPath library in perl
by Pickwick (Beadle) on Aug 05, 2010 at 11:39 UTC

    I installed XML::XPath using ppm for ActiveState and it worked out of the box with a little test program. I pretty sure I don't have libxml in my path or else. Does XML::LibXML work without any binary files or are they already integrated in perl.exe or did I just misunderstand something?

      I found a Stack Overflow question regarding adding XML::LibXML to an ActiveState distribution. It still requires the binary portions, but 3rd parties have made distributions and let you use the ActiveState ppm utility to get it installed.

      As to your original question about the utility of XML::XPath, it's not bad with relatively simple XML. It doesn't handle name spaces, and if your XML gets very large the memory usage and processing time is going to explode. For a project I was working on, I remember having to modify the code of XML::XPath a little to fix a bug in retrieving attribute values. It isn't actively maintained and you'll eventually outstrip its capabilities. If you don't want to bother with XML::LibXML, you could also try XML::Twig which has XPath capabilities.

Re: preferred XPath library in perl
by grantm (Parson) on Aug 05, 2010 at 22:12 UTC
    XML::LibXML is definitely the one you want. I'm pretty sure it's included in the Strawberry Perl distribution.