有关 org.dom4j.Node.numberValueOf 方法的一个说明

在 org.dom4j.Node 中可以用 numberValueOf 方法根据 XPath 表达式获取指定元素或者属性的数字类型的值。在 dom4j 的 API 文档中是这样注释的:

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.

但是,如果节点中存在多个符合 XPath 表达式的节点的话,numberVauleOf 方法实际上只会返回其中第一个节点的值。dom4j 中该方法是通过 org.jaxen.BaseXPath 中的同名方法来实现的,在 jaxen 的文档中,是这样注释的:

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 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值