XPath获取除具有特定名称的子元素以外的所有子元素? [英] XPath to get all child elements except one with specific name?

查看:154
本文介绍了XPath获取除具有特定名称的子元素以外的所有子元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何定位文档中的所有元素以外的特定元素名称?

How do I target all elements in a document except a particular element name?

例如,我想排除终止元素。它们可以出现在整个文档中。

For example I want to exclude the terminate elements. They can occur throughout the document.

 <root>
     <terminate attr="1" />
     <other>
         The brown fox jumps over the fence. 
         <terminate>
            <b>stuff</b>
         </terminate>
     </other>
 </root>

我尝试使用 not(..)运算符没有成功的可能是因为我用错了。

I've tried using the not(..) operator without success likely because I'm using it wrong.

坦率地说,尝试Google不并不容易!

And frankly trying to Google 'not' is tough!

推荐答案

以下xpath应该可以工作

The following xpath should work

/root/*[not(self::terminate)] 

另外,我认为您也可以这样做

Also, i think you can do it with this as well

/root/*[not(name()='terminate')]

这篇关于XPath获取除具有特定名称的子元素以外的所有子元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆