xpath not working

Topics: User Forum
Mar 5, 2011 at 3:33 PM
Edited Mar 5, 2011 at 3:36 PM

we have a simple html like this:

<html>
 <body>
   <div id="main">
     <div id="sub">
        <div>aaaa</a>
     </div>
   </div>
 </body>
</html>

C# code is:

foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//div[@id='sub']"))
{
        Response.Write(node.InnerHtml);
        Response.Write(node.SelectSingleNode("//div").InnerHtml);
        Response.Write(doc.DocumentNode.SelectSingleNode("//div").InnerHtml);
}
first response give us what we want, but second a third is the same - div with id "sub", from the second it should be the div from the node element, but it is the div from documentnode. So the second is searching in whole document. Is it ok? Shouldn't it search just in the node element?

thx