New user struggling

Topics: Developer Forum, User Forum
Mar 5, 2010 at 8:54 PM
Edited Mar 6, 2010 at 8:16 AM


I am trying to find all div elements that have a class="business"  attribute. If I try :

HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//div[@class='business']");

Here is some example html :

<div class="business">

  <div><p>nested div 1</p></div>

  <div><p>nested div 2</p></div>



The node collection (nc variable) contains the 2 nested divs but not the outer div (not the div with class="business" attribute. I've tried using / instead of // in the xpath, also no slashes at all but they return no results at all.




Mar 9, 2010 at 4:00 PM

Are you sure?

var doc2 = new HtmlDocument();
            doc2.LoadHtml("<div class=\"business\"><div><p>nested div 1</p></div><div><p>nested div 2</p></div></div>");
            HtmlNodeCollection nc = doc2.DocumentNode.SelectNodes("//div[@class='business']");


nc.Count == 1;