Java XPath Expression pathExists(XPath xpath, String expression, Object object)

Here you can find the source of pathExists(XPath xpath, String expression, Object object)

Description

Convenience method that performs an xpath evaluation to determine whether the expression evaluates to true (a node exists).

License

Educational Community License

Parameter

Parameter Description
xpath the XPath object
expression the XPath expression
object the object on which to evaluate the expression as required by the XPath API, typically a Node

Exception

Parameter Description
XPathExpressionException if the expression fails

Return

whether the result of the expression evaluation, which is whether or not a node was present

Declaration

public static boolean pathExists(XPath xpath, String expression, Object object)
        throws XPathExpressionException 

Method Source Code

//package com.java2s;
/**/*from   ww w. j a va  2  s.c om*/
 * Copyright 2005-2015 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;

public class Main {
    /**
     * Convenience method that performs an xpath evaluation to determine whether the expression
     * evaluates to true (a node exists).
     * This is method exists only to disambiguate the cases of determining the *presence* of a node
     * and determining the *boolean value of the node as converted from a string*, as the syntaxes
     * are very similar and could be misleading.
     *
     * @param xpath      the XPath object
     * @param expression the XPath expression
     * @param object     the object on which to evaluate the expression as required by the XPath API, typically a Node
     * @return whether the result of the expression evaluation, which is whether or not a node was present
     * @throws XPathExpressionException if the expression fails
     */
    public static boolean pathExists(XPath xpath, String expression, Object object)
            throws XPathExpressionException {
        return ((Boolean) xpath.evaluate(expression, object, XPathConstants.BOOLEAN)).booleanValue();
    }
}

Related

  1. loadNodeList(String file, String path)
  2. merge(XPathExpression expression, InputStream... files)
  3. modelPathExpr()
  4. parseXMLValue(String xml, String xpathExpression)
  5. parseXPath(String expression, NamespaceContext nsContext)
  6. readXmlNodeChildFromFile(String xPath, String path, NamespaceContext nsContext)
  7. replaceXPathNode(Node replaceThis, Node replaceWith)
  8. singleXPathNode(String expression, Node node)
  9. streamNodes(String xpath, Object node)