in reply to Re^4: Xpath not working
in thread Xpath not working
Even though TIMTOWTDI, I prefer writing this
Hah, my way :)
over this
Well, you only really need the first one ... unless all of a sudden the xml switches the default namespace ... which makes for weak xml
because it's shorter, has less repetition, and uses the recommended API... the XPath stuff is already where it belongs: in an XPath expression context.
Yes, the completely unspecified part of the api that is up to each implementer to implement
To use the recommended API xpather.pl would have to switch to printing perl code instead of xpaths ....
With xpather.pl you copy/paste the xpaths, edit minimally , practically no writing involved :) and even the dumbest newbie can copy/paste (and xml/xpath not exactly newbie friendly)
FWIW , this is F2.0
$node->F("//f:p/g:h", qw[ f http://f.example.com g http://g.example.co +m ]); sub XML::LibXML::Node::F { my $self = shift; my $xpath = shift; my %prefix = @_; our $XPATHCONTEXT; $XPATHCONTEXT ||= XML::LibXML::XPathContext->new(); while( my( $p, $u ) = each %prefix ){ $XPATHCONTEXT->registerNs( $p, $u ); } $XPATHCONTEXT->findnodes( $xpath, $self ); }
|
|---|