Created
April 28, 2012 04:10
-
-
Save carlosmcevilly/2515707 to your computer and use it in GitHub Desktop.
XPath debugging tool.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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