Here you can find the source of getString(final String xPath, final Object item)
Parameter | Description |
---|---|
xPath | the xpath expression to use |
item | the item to perform the xpath on |
Parameter | Description |
---|---|
XPathExpressionException | represents an error in an XPath expression |
public static String getString(final String xPath, final Object item) throws XPathExpressionException
//package com.java2s; //License from project: Apache License import javax.xml.namespace.QName; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; public class Main { /**// w w w. j a v a 2s .com * Evaluates the xpath on an object * * @param xPath * the xpath expression to use * @param item * the item to perform the xpath on * @return the evaluated object * @throws XPathExpressionException * represents an error in an XPath expression */ public static String getString(final String xPath, final Object item) throws XPathExpressionException { return (String) evaluateXPath(xPath, item, XPathConstants.STRING); } /** * 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); } }