tags:

views:

23

answers:

3

I would like to be able to find an element named 'test' with no attributes at all.

How can I do that using XPATH?

If i just query for /test it finds me all the test elements even with the ones that contain attributes.

example:

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

Querying for //test will find me both of the elements. I want only the one that contains no attributes. I can query for //test[not(@id)] but I was wondering if there is a command for an element with no attributes at all.

A: 

Query for test.

http://www.w3schools.com/XPath/xpath_syntax.asp

mcandre
that doesn't really help me. i updated main post with more info
ufk
A: 
<?xml version="1.0" encoding="windows-1250"?>
<test>
Oh hai
</test>

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

Not sure about your actual intent.

RandomNoob
updated main post with more info
ufk
+2  A: 

You almost had it. If you want to find the the test element(s) that have no attributes at all, use a wildcard match for the attribute name in your predicate filter:

//test[not(@*)]
Mads Hansen
thanks a lot! :)
ufk