XpathUtils.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:ibm-cos-sdk-java 作者:
/**
 * Evaluates the specified expression on the specified node and returns the
 * result as a String.
 *
 * @param expression
 *            The Xpath expression to evaluate.
 * @param node
 *            The node on which to evaluate the expression.
 *
 * @return The result of evaluating the specified expression, or null if the
 *         evaluation didn't return any result.
 *
 * @throws XPathExpressionException
 *             If there are any problems evaluating the Xpath expression.
 */
private static String evaluateAsString(String expression, Node node,
        XPath xpath) throws XPathExpressionException {
    if (isEmpty(node)) return null;

    if (!expression.equals(".")) {
        /*
         * If the expression being evaluated doesn't select a node, we want
         * to return null to distinguish between cases where a node isn't
         * present (which should be represented as null) and when a node is
         * present, but empty (which should be represented as the empty
         * string).
         *
         * We skip this test if the expression is "." since we've already
         * checked that the node exists.
         */
        if (asNode(expression, node, xpath) == null) return null;
    }

    String s = xpath.evaluate(expression, node);

    return s.trim();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号