Dom|treeview
Because of the recent need to use C # to handle the related operations of IE, some code has been accumulated, the following code is an example of the DOM TreeView generated from the HTML code:
This procedure will be called recursively
Dom_node is the current HTML DOM node
Tree_node is the node that is currently inserted into the tree
private void Insertdomnodes (Ihtmldomnode parentnode,treenode tree_node)
{
int sibing=0;//The order of the current node between sibling nodes, all nodes are separated by ","
if (Parentnode.haschildnodes ())
{
level++;
pathstring = pathstring + "," + level;
Ihtmldomchildrencollection allchild = (ihtmldomchildrencollection) parentnode.childnodes;
int length = Allchild.length;
for (int i=0;i<length;i++)
{
string instring = pathstring;
instring = instring + "," + sibing++;
Ihtmldomnode Child_node = (ihtmldomnode) allchild.item (i);
TreeNode Tempnode = Tree_node. Nodes.Add (Child_node.nodename + "_" +instring);
string tmp =
Insertdomnodes (Child_node,tempnode);
pathstring = instring;
}
}
}
private void Evipsbrowser_documentcomplete (object sender, Axshdocvw.dwebbrowserevents2_documentcompleteevent e)
{
PathString = "0";
level = 0;
DOMTreeView.Nodes.Clear ();
IHTMLDocument3 HTMLDocument = (IHTMLDocument3) evipsbrowser.document;
Ihtmldomnode Rootdomnode = (ihtmldomnode) htmldocument.documentelement;
TreeNode root = DOMTreeView.Nodes.Add ("HTML" + "_" +pathstring);
Insertdomnodes (Rootdomnode,root);
}