I need to select a small part of a XML document, in order to narrow my search space.
So far, I've created a Document, an Xpath object, I've searched into the whole Document and I've selected a subset of the original tags:
domFactory = DocumentBuilderFactory.newInstance();
builder = domFactory.newDocumentBuilder();
doc = builder.parse(inputXML);
xpath = XPathFactory.newInstance().newXPath();
.
.
NodeList de = (NodeList) xpath.evaluate("//secondBranch", doc, XPathConstants.NODESET);
However, when I try to find any tag inside
secondBranch, the evaluate() method brings me back
every tag inside the whole Document, not only the ones contained in
secondBranch subset:
for (int i=0; i<de. getLength();i++){
NodeList sq = (NodeList) xpath.evaluate("//lastLeaf", de.item(i), XPathConstants.NODESET);
}
sq contains all the
lastLeaf tags of the Document, not only the one contained in //secondBranch.
What am I doing wrong?
Thank you.