#!/usr/bin/perl -w use diagnostics; use strict; use XML::XPath; my $query; my @files; if (!($query = $ARGV[0])) { die "Must give a XPath query!$/"; } shift @ARGV; if (!(@files = @ARGV)) { die "Must give one or more filenames!$/"; } foreach my $file (@files) { if (!(-e "$file")) { print "File ($file) does not exist! Skipping...$/"; } else { my $xpath = XML::XPath->new(filename => $file); my $nodeset = $xpath->find($query); foreach my $node ($nodeset->get_nodelist) { print XML::XPath::XMLParser::as_string($node),$/; } } }