#!/usr/bin/perl use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file('atom.xml'); my $xpc = XML::LibXML::XPathContext->new; $xpc->registerNs('atom', 'http://www.w3.org/2005/Atom'); my $result = $xpc->find('//atom:category/attribute::term', $doc->documentElement); my %category; foreach my $node ($result->get*nodelist) { $category{$node->value}++; } foreach (sort {$category{$a} <=> $category{$b}} sort keys %category) { print $category{$*}, "\t", $_, "\n"; } $result = $xpc->find('//atom:entry', $doc->documentElement); print scalar($result->get_nodelist), " entries found.\n";