Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Xpath.evalute() ignores the context argument

843834Jan 21 2009 — edited Jan 21 2009
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2009
Added on Jan 21 2009
5 comments
113 views