开发者

xpath: how can i query for an element named test with no attributes at all?

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</tes开发者_Python百科t>
</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.


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(@*)]


Query for test.

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


<?xml version="1.0" encoding="windows-1250"?>
<test>
Oh hai
</test>

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

Not sure about your actual intent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜