/svg/text
looks for text
elements directly under the svg
root element. That is not what you have here. It looks like what you want is text
elements anywhere in the document, which would be //text
. This should work with XML::XPath.
If you want to use XML::LibXML, which you should since it is a much better module than XML::XPath (better maintained, more efficient, more powerful), then you have to pay attention to namespaces: the whole document has a default namespace (the xmlns="http://www.w3.org/2000/svg"
bit in the opening tag). You will need to declare it and use XML::LibXML::XPathContext to evaluate the XPath expression, including the prefix.:
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
use XML::LibXML::XPathContext;
# it's easier to test directly @ARGV in scalar context than to use $#ARGV
if(@ARGV != 1) { print "Usage: $0 <filename>\n"; exit(1); }
my $file=$ARGV[0];
my $doc = XML::LibXML->load_xml( location => $file);
my $xpc = XML::LibXML::XPathContext->new( $doc); # create the XPath evaluator
$xpc->registerNs(x => 'http://www.w3.org/2000/svg'); # declare the namespace as x
# the query now uses x as the prefix for the svg namespace
foreach my $dead ($xpc->findnodes('//x:text')) {
print "Found Text Node\n";
$dead->unbindNode;
}