Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Created April 28, 2012 04:10
Show Gist options
  • Save carlosmcevilly/2515707 to your computer and use it in GitHub Desktop.
Save carlosmcevilly/2515707 to your computer and use it in GitHub Desktop.
XPath debugging tool.
#!/usr/bin/perl
use XML::XPath;
use strict;
use warnings;
my $file = shift;
my $path = shift;
unless (defined($path) && -e $file) {
print STDERR "usage: $0 <infile> <path selector expression>\n\n";
print STDERR "under UNIX, use single quotes around expression.\n\n";
print STDERR "example: $0 test.xml '//phone[\@class=\"work\"]'\n\n";
exit(-1);
}
my $xp = XML::XPath->new( filename => $file );
my $ns = $xp->find($path);
foreach my $node ($ns->get_nodelist) {
print XML::XPath::XMLParser::as_string($node), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment