Hey everyone,

What's i'm trying to accomplish is this - I have a webbrowser control & a treeview control...once I load a website I create a HTML DOM tree representation of the website using the code below...

What I want to do now, is the following:

  1. mouse over any HTML element, which will then select the corresponding tree node on the HTML DOM Tree
  2. select any tree node and have the corresponding HTML element highlight, with a red border around it

Does anyone have any pointers / suggestions - I would really appreciate it...

Private Sub UpdateDOM(ByVal HTMLDocument As mshtml.IHTMLDocument3)
        Dim domRoot As mshtml.IHTMLElement = HTMLDocument.documentElement
        Dim treeRoot As New TreeNode()
        treeRoot.Text = "<html>"
        treeRoot.Tag = domRoot
        CopyElementToTree(domRoot, treeRoot)
    End Sub

    Private Shared Sub CopyElementToTree(ByVal element As mshtml.IHTMLElement, ByVal treeNode As TreeNode)
        Dim children As mshtml.IHTMLElementCollection = CType(element.children, mshtml.IHTMLElementCollection)

        If children.length <> 0 Then
            For Each e As mshtml.IHTMLElement In children
                Dim treeChild As New TreeNode()
                treeChild.Text = getAttrs(e)
                treeChild.Tag = e
                CopyElementToTree(e, treeChild)
            Next e
            If Not String.IsNullOrEmpty(element.innerText) Then
                Dim textNode As New TreeNode()
                textNode.Text = String.Format("""{0}""", element.innerHTML)
                textNode.Tag = element
            End If
        End If
    End Sub

    Private Shared Function getAttrs(ByVal element As mshtml.IHTMLElement) As String
        Dim result As New StringBuilder("<")
        Dim domnode As mshtml.IHTMLDOMNode = CType(element, mshtml.IHTMLDOMNode)
        Dim attrs As mshtml.IHTMLAttributeCollection = CType(domnode.attributes, mshtml.IHTMLAttributeCollection)
        If attrs IsNot Nothing Then
            For Each attr As mshtml.IHTMLDOMAttribute In attrs
                If Not attr.specified Then
                    Continue For
                End If
                result.Append(" ")
                Dim nodeValue As String = String.Empty
                If attr.nodeValue IsNot Nothing Then
                    nodeValue = attr.nodeValue.ToString()
                End If
                result.Append(String.Format("{0}=""{1}""", attr.nodeName, nodeValue))
            Next attr
        End If
        Return result.ToString()
    End Function

come on people...

I could really use some help here!! Please

thanks for your help folks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.