Here you can find the source of evaluateXPath(final String xPath, final Object item, final QName returnType)
Parameter | Description |
---|---|
xPath | the xpath expression to use |
item | the item to perform the xpath on |
returnType | the expected returntype of the evaluated expression |
Parameter | Description |
---|---|
XPathExpressionException | represents an error in an XPath expression |
public static Object evaluateXPath(final String xPath, final Object item, final QName returnType) throws XPathExpressionException
//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); } }