HTML agility pack's wildcard search in the node selector

c# html-agility-pack winforms

Question

I have this in my code.

<div>
<div style="PADDING-BOTTOM: 4px"> blah </div>
<div style="PADDING-BOTTOM: 2px"> blah </div>
<div>

How do I choose the second and third divs in "node.SelectNodes"?

HtmlNode node = doc.DocumentNode.SelectSingleNode(".//div[@style='PADDING-BOTTOM: 2px']");

Can I use any other px, such as 2px and 4px, in a wilcard search?

1
2
5/16/2012 4:41:21 PM

Accepted Answer

You may utilizecontains() to perform a match between strings.

node = doc.DocumentNode.SelectSingleNode(".//div[contains(@style, 'PADDING-BOTTOM:')]");
4
5/16/2012 4:45:04 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow