由于最近需要使用c#进行ie的相关编程,因此特整理出相应的代码出来,下面的代码是访问html,并生成treeview dom书的代码:
private void insertdomnodes(ihtmldomnode parentnode,treenode tree_node)
{
if(parentnode.haschildnodes())
{
ihtmldomchildrencollection allchild = (ihtmldomchildrencollection)parentnode.childnodes;
int length = allchild.length;
for(int i=0;i<length;i++)
{
ihtmldomnode child_node = (ihtmldomnode)allchild.item(i);
treenode tempnode = tree_node.nodes.add(child_node.nodename);
insertdomnodes(child_node,tempnode);
}
}
}
//将domnode插入
private void evipsbrowser_documentcomplete(object sender, axshdocvw.dwebbrowserevents2_documentcompleteevent e)
{
domtreeview.nodes.clear();
ihtmldocument3 htmldocument =(ihtmldocument3)evipsbrowser.document;
ihtmldomnode rootdomnode = (ihtmldomnode)htmldocument.documentelement;
treenode root = domtreeview.nodes.add("html");
insertdomnodes(rootdomnode,root);
}
新闻热点
疑难解答