g1ga
g1ga

Reputation: 322

xpath syntax meaning

I'm trying to understand a piece of code I should manage. I found some html manipulation in which HtmlAgilityPack is used for some node selection. Someone knows the meaning of this xpath selector?

//table/*[not(self::tr or self::tbody)]

Upvotes: 3

Views: 352

Answers (2)

Wayne
Wayne

Reputation: 60424

In English:

Select any element node (*) such that it is not itself a tr or tbody ([not(self::tr or self::tbody)]) and that is the child of a table element that could appear anywhere in the document (//table).

It is equivalent to the following un-abbreviated expression

/descendant-or-self::node()/child::table/child::*[not(self::tr or self::tbody)]

Upvotes: 2

AakashM
AakashM

Reputation: 63378

self is a handy way of referring to the name of the element node under consideration, without namespaces.

In this example, we will match any element which is a child of a table, and is not a tr or a tbody.

Upvotes: 2

Related Questions