title: .html file > HTMLAgilityPack > TreeView Hierarchy
body: <p>Using HTMLAgilityPack + TreeView to create a hierarchy GUI of an HTML file. The HTML file is CMS-generated, and not very well generated at that.</p>
  
  <p>Needs to do the following:
  1. Read each <em>Outline Level 0</em> node into the TreeView.</p>
  
  <pre><code>HtmlNodeCollection ZeroLevelNodes = doc.DocumentNode.SelectNodes("//body/object[@type='text/sitemap']|//body/ul/object[@type='text/sitemap']|//body/ul/li/object[@type='text/sitemap']");
  </code></pre>
  
  <p>2. Read the Outline Level 1 nodes as children of their respective Outline Level 0 nodes
     <strong>Note:</strong> Each Outline Level 0 node (minus a few that aren't important for this question) are layed out as <code>&lt;li&gt;&lt;object&gt;&lt;param /&gt;&lt;/object&gt;</code> (notice the lack of a closing <code>&lt;/li&gt;</code> tag). The nodes that need to appear as children in the TreeView will be in an unordered list <code>&lt;ul&gt;</code> that is the next sibling of a level 0 node's <code>&lt;li&gt;</code> tag, for example:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;
          &lt;object&gt;
              &lt;param name="**exampleLevel0**" value="**example.htm**" /&gt; //value example.htm as the text in the level 0 node.
          &lt;/object&gt;
      &lt;ul&gt;
          &lt;li&gt;
              &lt;object&gt;
                 &lt;param name="**ExampleLevel1**" value="childnode.htm" /&gt; //childnode.htm as the text in the level 1 child node.
              &lt;/object&gt;
          &lt;li&gt;
              &lt;object&gt;
                 &lt;param name="**ExampleLevel1_2**" value="childnode2.htm" /&gt; //childnode2.htm as the text in the level 1 child node.
              &lt;/object&gt;
      &lt;/ul&gt;
   &lt;/ul&gt;
  </code></pre>
  
  <p>Here is my current code to generate the top-level of hierarchy</p>
  
  <pre><code>HtmlNodeCollection tocNodes = doc.DocumentNode.SelectNodes("//body/object[@type='text/sitemap']|//body/ul/object[@type='text/sitemap']|//body/ul/li/object[@type='text/sitemap']");
  foreach (HtmlNode zeroLevelNode in zeroLevelNodes)
          {
  
              TreeNode tNode = new TreeNode();
              HtmlNode paramNode = zeroLevelNode.SelectSingleNode("param[@name]");
              string paramName = paramNode.GetAttributeValue("name", null);
              string paramValue = paramNode.GetAttributeValue("value", null);
              TreeView.Nodes.Add(new TreeNode(paramValue));
              tNode = TreeView.Nodes[i];
              AddNode(zeroLevelNode, tNode);
              i += 1;
          }
  </code></pre>
  
  <p>Could anyone give me a hand with the code needed to load the "children" (outline level 1) nodes into the TreeView? (AddNode(zeroLevelNode, tNode)</p>