Just creating an XML::LibXML:XPathContext
object won't make any difference, you also need to register all the namespaces that you want to use in your XPath expressions. In this case you've used the ns2
namespace without registering any namespaces at all
Your code should look something like this
my $xml = XML::LibXML->new->parse_file("$tmp_dir/xml/$xml_file_name");
my $xc = XML::LibXML::XPathContext->new($xml);
$xc->RegisterNs( ns2 => 'http://example.com/ns2/uri/address');
my $val = $xc->findvalue('/ns2:export/ns2:bankGuarantee/docPublishDate');
print $val;
Note that the URI you register has to match the one in the
xmlns:ns2="http://example.com/ns2/uri/address"
attribute in the data
I'm wondering if the clean_namespaces
parser option is your attempt to fix this? clean_namespaces
will only remove redundant namespaces, i.e. those that aren't used anywhere in the XML document. There's little point in doing that as you stand little chance of the namespaces clashing, and the time and memory saved will be negligible