Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath: get nodes that do not have an X ancestor

Tags:

xml

xpath

I want all nodes of an xml document that are not descendants of nodes X.

(My actual problem is a little more complex, but I'm stuck with the "are not descendants" part right now).

like image 276
flybywire Avatar asked Feb 01 '10 13:02

flybywire


People also ask

What is an ancestor node in XPath?

Definition of XPath Ancestor. The ancestor axis chooses all of the current node's ancestor elements (parent, grandparent, great-grandparents, and so on). The root node is always present on this axis (unless the current node is the root node).

Can you use XPath expression used to select the target node and its values?

XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.


1 Answers

If you translate "are not descendants" to "have no ancestor", you get the expression //*[not(ancestor::X)]. This will return all nodes in a document, which are not descendants of nodes named "X".

like image 171
jarnbjo Avatar answered Oct 05 '22 02:10

jarnbjo