To correct my first sentence of the parent and expand the explanation a little:
Your line $doc->documentElement->setNamespace("http://www.crtp.it","p"); does not work, and the documentation of XML::LibXML::Element->setNamespace explains why:
The function fails if it is required to create a declaration associating the prefix with the namespace URI but the element already carries a declaration with the same prefix but different namespace URI.
Which means you can't re-use the "p" prefix as it's already in use on the element; you'd have to pick a different prefix, then the setNamespace call would work and you wouldn't need to do registerNs on two namespaces.
However, you would still need to make one XML::LibXML::XPathContext->registerNs set-up as shown in the parent.
So TIMTOWTDI; personally I wouldn't manipulate the XML, but adjust my XPath to fit the XML (this is the solution shown in the parent, and you could remove the setNamespace call from your code).
In reply to Re^2: Xpath not working
by Anonymous Monk
in thread Xpath not working
by njack
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |