Necesito restringir la búsqueda del nodo xpath a un subárbol. Actualmente estoy usando el método siguiente, pero busca en todo un documento si le doy el documento o el nodo del que quiero buscar.xpath buscar en el subárbol
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);
}
solución que estoy usando ahora es que puedo crear nuevo documento, añada el nodo y buscar en el nuevo documento, y luego fusionar. Quiero mejorar esto. Se puede hacer?
El XPath que estoy usando es //nodeName
.
nos muestran el XPath que está utilizando – soulcheck
creo que la restricción tendría que hacerse en la expresión XPath. – McDowell
agregué el xpath en la edición. –