但是,如果节点中存在多个符合 XPath 表达式的节点的话,numberVauleOf 方法实际上只会返回其中第一个节点的值。dom4j 中该方法是通过 org.jaxen.BaseXPath 中的同名方法来实现的,在 jaxen 的文档中,是这样注释的:numberValueOf
public Number numberValueOf(String xpathExpression)
numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.
Parameters:
xpathExpression - is the XPath expression to be evaluated
Returns:
the numeric result of the XPath expression or null if the result is not a number.
numberValueOf
public Number numberValueOf(Object node)
throws JaxenException
Retrieve a number-value interpretation of this XPath expression when evaluated against a given context.
The number-value of the expression is determined per the number(..) core function as defined in the XPath specification. This means that if this expression selects multiple nodes, the number-value of the first node is returned.
Specified by:
numberValueOf in interface XPath
Parameters:
node - the node, node-set or Context object for evaluation. This value can be null.
Returns:
a Double indicating the numeric value of evaluating this expression against the specified context
Throws:
JaxenException - if an XPath error occurs during expression evaluation