title: Html Agility Pack - Problem selecting subnode
body: <p>I want to export my Asics running plan to iCal and since Asics do not offer this service, I decided to build a little scraper for my own personal use. What I want to do is to take all the scheduled runs from my plan and generate an iCal feed based on that. I am using C# and Html Agility Pack.</p>
  
  <p>What I want to do is iterate through all my scheduled runs (they are div nodes). Then next I want to select a few different nodes with my run nodes. My code looks like this:</p>
  
  <pre><code>foreach (var run in doc.DocumentNode.SelectSingleNode("//div[@id='scheduleTable']").SelectNodes("//div[@class='pTdBox']"))
  {
      number++;
      string date = run.SelectSingleNode("//div[@class='date']").InnerText;
      string type = run.SelectSingleNode("//span[@class='menu']").InnerHtml;
      string distance = run.SelectSingleNode("//span[@class='distance']").InnerHtml;
      string description = run.SelectSingleNode("//div[@class='description']").InnerHtml;
      ViewData["result"] += "Dato: " + date + "&lt;br /&gt;";
      ViewData["result"] += "Tyep: " + type + "&lt;br /&gt;";
      ViewData["result"] += "Distance: " + distance + "&lt;br /&gt;";
      ViewData["result"] += "Description: " + description + "&lt;br /&gt;";
      ViewData["result"] += run.InnerHtml.Replace("&lt;", "&amp;lt;").Replace("&gt;", "&amp;gt;") + "&lt;br /&gt;" + "&lt;br /&gt;" + "&lt;br /&gt;";
  }
  </code></pre>
  
  <p>My problem is that <code>run.SelectSingleNode("//div[@class='date']").InnerText</code> does not select the node with the given XPath within the given run node. It selects the first node that matches the XPath in the entire document.</p>
  
  <p>How can I select the single node with the given XPath within the current node?</p>
  
  <p>Thank you.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I tried updating my XPath string to this:</p>
  
  <pre><code>string date = run.SelectSingleNode(".div[@class='date']").InnerText;
  </code></pre>
  
  <p>This should select the <code>&lt;div class="date"&gt;&lt;/div&gt;</code> element within the current node, right? Well, I tried this but got this error:</p>
  
  <blockquote>
    <p>Expression must evaluate to a
    node-set. Description: An unhandled
    exception occurred during the
    execution of the current web request.
    Please review the stack trace for more
    information about the error and where
    it originated in the code.</p>
    
    <p>Exception Details:
    System.Xml.XPath.XPathException:
    Expression must evaluate to a
    node-set.</p>
  </blockquote>
  
  <p>Any suggestions?</p>