Perl Libxml Get Last Line Number Of Node
I use LibXML in Perl, which store the start line number of each node, but how i can get the last one? I tried get last line number through.. ..counting newlines in innerhtml of th
Solution 1:
If line_number
returned the first line of a node as you say, all you'd need is
my $s_line_num = $node->line_number();
my $e_line_num = $node->nextSibling()->line_number();
But it doesn't. What line_number
returns is actually closer the number of the last line of the node. For that, we could simply look at the previous sibling's line number.
my $s_line_num = $node->previousSibling()->line_number();
my $e_line_num = $node->line_number();
But while that's what it returns for non-element nodes, it returns the last line number of the start tag (rather than of the element as a whole) for elements. That's completely useless.
Sorry, no can do!
Solution 2:
If line_number returned the first line of a node as you say, all you'd need is
my $parser = XML::LibXML->new( XML_LIBXML_LINENUMBERS==>1);
my $e_line_num = $node->line_number();
=> 1 );
Post a Comment for "Perl Libxml Get Last Line Number Of Node"