#!/usr/bin/perl -- use strict; use warnings; use XML::LibXML; my $doc = XML::LibXML->new()->parse_string( q{ } ); for my $node ( $doc->F( '//x:sham' ) ) { print "@{[ $node->nodePath ]}\n"; for my $name ( $node->F( 'x:bo/@name' ) ) { print "@{[ $name->nodePath ]} @{[$name->nodeValue]}\n"; } print "\n\n"; } $::xpc->registerNs( 'y', 'http://example.com/roshambo' ); print $doc->F('y:roshambo'); exit( 0 ); BEGIN { $::xpc = XML::LibXML::XPathContext->new( ); $::xpc->registerNs( 'x', 'http://example.com/roshambo' ); sub XML::LibXML::Node::F { my( $self, $xpath, $context ) = @_; $::xpc->findnodes( $xpath, $context || $self ); } } __END__