HTMLAgilityPack Selectnodes always returns null
<p>I heard good things about the HTMLAgilityPack library, so I thought I'd give it a try but I have had absolutely zero success with it. I've been trying to figure this out for months. No matter what I do, I cannot get this code to give me anything other than null. I tried following this example (<a href="http://www.c-sharpcorner.com/uploadfile/9b86d4/getting-started-with-html-agility-pack/" rel="nofollow">http://www.c-sharpcorner.com/uploadfile/9b86d4/getting-started-with-html-agility-pack/</a>), but I do not get the same results and I cannot explain why.</p>

<p>I try loading the file and then run SelectNodes to select all hyperlinks, but it always returns an empty list. I've tried selecting all kinds of nodes (divs, p, a, everything and anything) and it always returns an empty list. I've tried using doc.Descendants, I've tried using different source files, locally and on the the web and nothing I do will ever return an actual result.</p>

<p>I must have overlooked something important, but I cannot figure out what it is. What could I be missing? </p>

<p>Code:</p>

<pre><code>    public string GetSource()
    {
        try
        {
            string result = "";

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            if (!System.IO.File.Exists("htmldoc.html"))
                throw new Exception("Unable to load doc");

            doc.LoadHtml("htmldoc.html");   // copied locally to bin folder, confirmed it found the file and loaded it

            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//a");  // Always returns null, regardless of what I put in here

            if (nodes != null)  
            {
                foreach (HtmlNode item in nodes)
                {
                    result += item.InnerText;
                }
            }
            else
            {
                // Every. Single. Time.
                throw new Exception("No matching nodes found in document");
            }


            return result;
        }
        catch (Exception ex)
        {                
            return ex.ToString();
        }
    }
</code></pre>

<p>The source HTML file 'htmldoc.html' I'm using looks like this:</p>

<pre><code>&lt;html&gt;  
&lt;head&gt;  
    &lt;title&gt;Testing HTML Agility Pack&lt;/title&gt;
&lt;/head&gt;  
&lt;body&gt;  
    &lt;div id="div1"&gt;  
        &lt;a href="div1-a1"&gt;Link 1 inside div1&lt;/a&gt;  
        &lt;a href="div1-a2"&gt;Link 2 inside div1&lt;/a&gt;  
    &lt;/div&gt;  
        &lt;a href="a3"&gt;Link 3 outside all divs&lt;/a&gt;      
        &lt;div id="div2"&gt;  
        &lt;a href="div2-a1"&gt;Link 1 inside div2&lt;/a&gt;  
        &lt;a href="div2-a2"&gt;Link 2 inside div2&lt;/a&gt;  
    &lt;/div&gt;  
&lt;/body&gt;  
&lt;/html&gt;
</code></pre>