VBobCat
Well-known member
Hello people,
I wrote this code in order to parse HTML elements within an HTML document into a treeview, so I can study its structure. But my iteration must have something wrong, for it doesn't recover all the elements. Could someone help me to fix it? Thank you very much!
I wrote this code in order to parse HTML elements within an HTML document into a treeview, so I can study its structure. But my iteration must have something wrong, for it doesn't recover all the elements. Could someone help me to fix it? Thank you very much!
Public Sub ShowDocument(ByVal document As HtmlDocument)
TreeView1.BeginUpdate()
TreeView1.Nodes.Clear()
Dim ActElem As HtmlElement, ActNode As TreeNode, ActStem As TreeNodeCollection
ActElem = document.Body.Parent
ActStem = TreeView1.Nodes
Do
If ActElem Is Nothing Then Exit Do
ActNode = New TreeNode With {.Text = ActElem.TagName, .Tag = ActElem.OuterHtml}
ActStem.Add(ActNode)
If ActElem.Children.Count > 0 Then
ActElem = ActElem.FirstChild
ActStem = ActNode.Nodes
Else
Do While ActElem.NextSibling Is Nothing
If ActElem = document.Body.Parent Then Exit Do
ActElem = ActElem.Parent
ActStem = ActNode.Parent.Parent.Nodes
Loop
ActElem = ActElem.NextSibling
End If
Loop
TreeView1.EndUpdate()
Me.Show()
End Sub