【发布时间】:2023-03-24 18:21:02
【问题描述】:
我正在使用XML::LibXML,我只需要获取由 XPath 表达式指定的节点数。
使用下面的前两个代码行中的任何一个都会产生我正在寻找的内容。我可以将count XPath 函数与findvalue 或find 一起使用,但不能与findnodes 一起使用(是的,我知道,因为它返回一个列表)。
my $node_cnt = $dom->findvalue("count($xpath_str)"); # WORKS!
my $node_cnt = $dom->find("count($xpath_str)"); # WORKS!
my @node_cnt = $dom->findnodes("count($xpath_str)"); # count doesn't work!
这导致我提出一个普遍的唠叨问题:
三种find 类型有什么区别?在文档中,它说:
$string = $node->findvalue($xpath)
$result = $node->find($xpath)
@nodes = $node->findnodes($xpath_expression)
文档中的参数
$xpath_expression和$xpath之间真的有区别吗?对于返回标量的两个,有什么区别?
我试图了解使用一种查找类型而不是另一种查找类型的重要性 - 谢谢!
【问题讨论】: