I need to restrict the xpath node search to a subtree. I'm currently using the method below but it searches on a whole document regardlest whether I give it the document or the node I want to search from.
private NodeList findNodes(Object obj,String xPathString) throws ... {
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression expression = xPath.compile(xPathString);
return (NodeList) expression.evaluate(obj, XPathConstants.NODESET);
}
Solution I'm using now is that I create new document, append the node and search on the new document, then merge. I want to improve this. Can it be done?
The XPath I'm using is //nodeName
.