I am trying to process a XML with XML::LibXML and report lines where certain elements are. According to docs linked above, line_numbers option should do the trick, but I keep getting 0. The code:
use XML::LibXML;
my $parser = XML::LibXML->new({ line_numbers => 1 });
my $xml = $parser->load_xml(location => 'some.xml');
for my $node ($xml->findnodes('//function')) {
warn $node->nodePath,"\n";
warn $node->line_number,"\n";
}
The node is found, my output is
/database/functions/function
0
Any idea how to get it working?
From the documentation:
Was the node added during the course of the XML manipulation?
It wasn’t. A closer investigation showed that the offending function was the
load_xml. Replace it with the following and it works fine: