Java xpath, select deepest children
I am new to Java and XPath syntax. I have a complex XML document. I need to select all nodes that have no children (I really need their values).
<root>
<a>
<b>text1</b>
<c>text2</c>
</a>
<d>
<e>
<f>text3</f>
</e>
</d>
<f>text4</f>
</root>
I want to get a list "text1","text2","text3","text4"
here. Could you please help me with the xpath expression? Thank.
+3
Timofei Davydik
source
to share
3 answers
Ok this is what i need
root.selectNodes("//*[not(*)]")
+7
Timofei Davydik
source
to share
I need to select all nodes that have no children
I suspect you want to select all elements that have no children. It will be //*[not(*)]
.
+2
Michael kay
source
to share
If the document is above, try it //*/text()
;)
0
Sjaak Trekhaak
source
to share