Java XPath Evaluate evaluateXPath(final String xPath, final Object item, final QName returnType)

Here you can find the source of evaluateXPath(final String xPath, final Object item, final QName returnType)

Description

Evaluates the xpath on an object

License

Apache License

Parameter

Parameter Description
xPath the xpath expression to use
item the item to perform the xpath on
returnType the expected returntype of the evaluated expression

Exception

Parameter Description
XPathExpressionException represents an error in an XPath expression

Return

the evaluated object

Declaration

public static Object evaluateXPath(final String xPath, final Object item, final QName returnType)
        throws XPathExpressionException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;

import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

public class Main {
    /**/*from  w ww  .  j a v  a  2 s.  c  om*/
     * Evaluates the xpath on an object
     * 
     * @param xPath
     * the xpath expression to use
     * @param item
     * the item to perform the xpath on
     * @param returnType
     * the expected returntype of the evaluated expression
     * @return the evaluated object
     * @throws XPathExpressionException
     * represents an error in an XPath expression
     */
    public static Object evaluateXPath(final String xPath, final Object item, final QName returnType)
            throws XPathExpressionException {
        XPath xpath = XPathFactory.newInstance().newXPath();
        XPathExpression expr = xpath.compile(xPath);
        return expr.evaluate(item, returnType);
    }
}

Related

  1. evaluateNodes(final XPathExpression xpathExpression, final Document pom)
  2. evaluateNodeSet(XPathExpression xpe, Object item)
  3. evaluateXpath(Document doc, String xpath, QName returnType)
  4. evaluateXPath(Element element, String xpathstring)
  5. evaluateXpath(Element from, String xpath)
  6. evaluateXPath(final XPathExpression expr, final Object rootNode, final QName returnType)
  7. evaluateXPath(Node node, String xPath)
  8. evaluateXpath(String expression, Document document, QName dataType)
  9. evaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext)