问题描述
我在Perl中使用LibXML,它存储每个节点的起始行号,但我怎么能得到最后一个?
..
- ..在节点的innerhtml中计算换行符,但是LibXML以不同于原始格式的格式返回innerhtml,以便行号
- .. node-> getLastChild-> line_number,但也没有成功。
line_number 返回了第一行如你所说,所有你需要的是
my $ s_line_num = $ node-> line_number();
my $ e_line_num = $ node-> nextSibling() - > line_number();
但事实并非如此。什么 line_number
返回实际上更接近该节点的最后一行的数量。
my $ s_line_num = $ node-> previousSibling() - > LINE_NUMBER();
my $ e_line_num = $ node-> line_number();
虽然这是非元素节点返回的结果,但它返回开始的最后一行数标记(而不是整个元素)作为元素。这完全没用。
对不起,不能做!
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 the node, but LibXML return the innerhtml in different formatting than original, so that the line number differ.
- ..node->getLastChild->line_number, but also havin no success.
Any Idea?
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!
这篇关于Perl LibXML获取节点的最后一行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!