Xpath: how can I request an element named test without attributes?

I would like to find an element named "test" with no attributes at all.

How can I do this using XPATH?

If I just query /test, it finds all the elements test, even those that contain attributes.

Example:

<main>
<test id="test1">txt</test>
<test>txt2</test>
</main>

The query for //testwill find for me both elements. I want only one that does not contain attributes. I can ask //test[not(@id)], but I was wondering if there is a command for an element with no attributes at all.

+3
source share
3 answers

. test, , :

//test[not(@*)]
+6
<?xml version="1.0" encoding="windows-1250"?>
<test>
Oh hai
</test>

test = / test
Oh hai = / test / text ()

Not sure about your actual intention.

0
source

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


All Articles