message1 mess...">

How to select node without attributes using xpath?

Say I have xml:

<root>
    <node light="somevalue">message1</node>
    <node dark="somevalue">message2</node>
    <node>message3</node>
</root>

When using xpath I need to get "message3".

Does anyone know how I can achieve this?

+3
source share
2 answers

I think you mean that you want to select nodes without attributes.

From XPath: how to select nodes that have no attributes?

//node[not(@*)]

This will select all nodes that do not have attributes.

+5
source
/root/node[not(@*)]/text()
+4
source

Source: https://habr.com/ru/post/1761528/


All Articles