[Edinburgh-pm] XML module recommendations

Aaron Crane perl at aaroncrane.co.uk
Mon Jun 6 11:12:07 PDT 2011

Miles Gould <miles at assyrian.org.uk> wrote:
> I'd like to extract a list of all the hashes: ie, the content of every
> attribute matching the XPath /changelog/patch/@hash. What's the best
> CPAN module for that sort of thing?

I'm fond of XML::LibXML — it's fast (because it wraps a fast C
library, libxml2), and it has built-in XPath querying.  It's also
familiar to anyone who's comfortable with DOM interfaces.

So, for your task:

use XML::LibXML;

my $doc = XML::LibXML->load_xml(location => $filename);
say $_->value for $doc->findnodes('/changelog/patch/@hash');

> [I know what you're thinking: why don't you build darcs as a set of
> libraries and write a Haskell program that links against libdarcs and
> queries the data-structures directly? The question answers itself, I
> feel.]

I couldn't possibly comment, minister.

Aaron Crane ** http://aaroncrane.co.uk/

More information about the Edinburgh-pm mailing list