Is it because the bar
namespace has not been registered yet? If I add $xpc2->registerNs('bar', 'www.bar.com');
just before the unregisterNs
call, the program runs fine for me. Does this produce the behavior you want?
Update from the additional information:
The way you're doing your query may be revealing a bug in libxml or XML::LibXML; I'm not familiar enough with XPathContext to know if it is a bug or not. So I tried something that confuses me, I did a lookupNS
after I did the unregisterNS
and I still got the correct NS:
$xpc2->registerNs('bar', 'www.bar.com');
$xpc2->unregisterNs('bar');
print $xpc2->lookupNs('bar') . "\n"; # print www.bar.com
However, I may have a solution that does what you're looking for. Instead of using 'bar'
as the prefix I tried using 'bob'
instead and I think it may give you the behavior you're looking for:
$xpc2->registerNs('bob', 'www.bar.com');
$xpc2->unregisterNs('bob');
my @nodes = $xpc2->find('bob:id');
print scalar @nodes . "\n";
Doing it this way causes the find
method to throw an exception. The code will not get to the print scalar
command.