I'm trying to run the same query on several different contexts, but I always get the same result. This is an example xml:
<root>
<p>
<r>
<t>text</t>
</r>
</p>
<t>text2</t>
</root>
So this is what I'm doing:
final XPath xpath = XPath.newInstance("//t");
List<Element> result = xpath.selectNodes(thisIsThePelement);
// and I've debuged it, it really is the <p> element
And I always get both <t>
elements in the result list.
I need just the <t>
inside the <p>
I'm passing to the XPath
object.
Any ideas would be of great help, thanks.
You're using
"//t"
as your XPath expression, which means precisely "find allt
elements in the document".To only find the descendant
t
elements from the context node, use".//t"
.See the "abbreviated syntax" part of the XPath spec for more details.