Java Utililty Methods XPath Evaluate

List of utility methods to do XPath Evaluate

Description

The list of methods to do XPath Evaluate are organized into topic(s).

Method

ObjectexecuteXPath(Document dom, String xpath, QName returnType)
execute X Path
XPathExpression expr = XPathFactory.newInstance().newXPath().compile(xpath);
return expr.evaluate(dom, returnType);
NodeListexecuteXPathExpression(Document document, String expression)
execute X Path Expression
NodeList nodeList = null;
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr;
try {
    expr = xpath.compile(expression);
    nodeList = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
...
ObjectexecXPath(org.w3c.dom.Node node, String pattern, QName xPathConstantsType)
exec X Path
return XPathFactory.newInstance().newXPath().compile(pattern).evaluate(node, xPathConstantsType);
StringfindNodeAndGetXPath(String qName, String fileName)
find Node And Get X Path
return getFullXPath(findNode(qName, fileName));
ObjectgetNodesListXpath(final String xPathS, final Node node, final String nsuri, final String pre, final QName returnType)
get Nodes List Xpath
Object matches = null;
System.setProperty("javax.xml.xpath.XPathFactory:" + XPathConstants.DOM_OBJECT_MODEL, XPATH_FACTORY);
XPathFactory xpathFactory = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
XPath xpath = xpathFactory.newXPath();
XPathExpression xpe = xpath.compile(xPathS);
matches = xpe.evaluate(node, returnType);
return matches;
StringparseVariable(Node contextNode, String xPathString)
parse Variable
String varName = null;
return varName;
TxPath(final Node aNode, final String anXPath, final QName aQName)
x Path
return (T) xPath.compile(anXPath).evaluate(aNode, aQName);
ListxpathEvalElements(String expr, Object e)
xpath Eval Elements
NodeList nl = xpathEvalNodes(expr, e);
List<Element> res = new ArrayList<Element>();
for (int i = 0; i < nl.getLength(); i++) {
    res.add((Element) nl.item(i));
return res;
NodeListxpathEvalNodes(String expr, Object e)
xpath Eval Nodes
return (NodeList) xpathEval(expr, e, XPathConstants.NODESET);