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


source to share


3 answers


Ok this is what i need



root.selectNodes("//*[not(*)]")

      

+7


source


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


source


If the document is above, try it //*/text()

;)

0


source







All Articles