'Java xpath, select most deep children
I'm new to Java and XPath syntax. I have complex xml document. What I need is to select all the nodes, that don't have children (I need their values actually).
<root>
<a>
<b>text1</b>
<c>text2</c>
</a>
<d>
<e>
<f>text3</f>
</e>
</d>
<f>text4</f>
</root>
I want to get list "text1","text2","text3","text4" here. Could you help me with XPath expression?
Solution 1:[1]
Ok, this is, what I need
root.selectNodes("//*[not(*)]")
Solution 2:[2]
What I need is to select all the nodes, that don't have children
I suspect you mean you want to select all the elements that don't have element children. That would be //*[not(*)].
Solution 3:[3]
If the document is as above, try //*/text() ;)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Timofei Davydik |
| Solution 2 | Michael Kay |
| Solution 3 | Sjaak Trekhaak |
