XPath获取除具有特定名称的子元素以外的所有子元素?

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')]