htmlagility treeview

Solutions on MaxInterview for htmlagility treeview by the best coders in the world

showing results for - "htmlagility treeview"
Gabriela
03 May 2017
1HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
2doc.LoadHtml(html);
3TreeNode root = new TreeNode("HTML");
4treeView1.Nodes.Add(root);
5
6LoadTree(root, doc.DocumentNode);
7
8
9void LoadTree(TreeNode treeNode, HtmlAgilityPack.HtmlNode rootNode)
10{
11    foreach (var node in rootNode.ChildNodes.Where(n=>n.Name!="#text"))
12    {
13        TreeNode n = new TreeNode(node.Name);
14        node.Attributes.Select(a => a.Name + "=" + a.Value)
15                       .ToList()
16                       .ForEach(x => n.Nodes.Add(x));
17        treeNode.Nodes.Add(n);
18
19        LoadTree(n, node);
20    }
21}