简体   繁体   English

如何使用xpath选择没有属性的节点?

[英]How to select a node without attributes using xpath?

Let say that I have xml like this: 假设我有这样的xml:

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

With xpath usage I need to get "message3". 使用xpath时我需要获取“message3”。

Does anybody know how I can achieve this? 有谁知道我怎么能做到这一点?

I think you mean that you want to select nodes without attributes. 我认为你的意思是你想要选择没有属性的节点。

From XPath: How to select nodes which have no attributes? 来自XPath:如何选择没有属性的节点?

//node[not(@*)]

This will select all nodes that do not have attributes. 这将选择所有没有属性的节点。

/root/node[not(@*)]/text()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM