Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java xpath, select most deep children

Tags:

java

xml

xpath

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?

like image 965
Timofei Davydik Avatar asked Dec 21 '22 23:12

Timofei Davydik


1 Answers

Ok, this is, what I need

root.selectNodes("//*[not(*)]")
like image 198
Timofei Davydik Avatar answered Jan 01 '23 09:01

Timofei Davydik