Reputation: 3180
I'm using HTMLAgilityPack to grab a bunch of a tags. Some of the have 1 of several classes assigned and some have no class. It's those with no class that I need to grab.
I know that to grab a node by class we can do something like;
.SelectNodes("//table[@class=\"pagelinks\"]");
Similarly you can choose to ignore specific classes or id's with;
.SelectNodes("//table[not(@class=\"pagelinks\")]");
But is there a way to only grab a node when and only when it has no class?
Upvotes: 1
Views: 734
Reputation: 101662
This XPath will select tables that either have no class
attribute, or that have a class
attribute that is entirely whitespace (or blank):
//table[not(normalize-space(@class))]
Upvotes: 3
Reputation: 589
The following code should select when there's no class attribute defined at all:
.SelectNodes("//table[not(@class)]");
Upvotes: 5