sfarzoso
sfarzoso

Reputation: 1600

How to get only div with not style attribute?

Suppose I have the following html structure:

<div class="table-container"></div>
<div class="table-container" style="display: none;"></div>
<div class="table-container" style="display: none;"></div>
<div class="table-container"></div>

how can I get only the div with no style attribute? I did this:

HtmlNodeCollection containers = doc.DocumentNode.SelectNodes("//div[@class='table-container']");

there is a property that allow me to do that?

Upvotes: 1

Views: 116

Answers (1)

OfirD
OfirD

Reputation: 10460

Your'e close. Just add a Where:

var nodes = doc
   .DocumentNode
   .ChildNodes
   .Where(n => n.Attributes.Count == 1 && 
               n.Attributes[0].Name == "class")
   .ToList();

Upvotes: 2

Related Questions