最近Iで関連する操作を処理するためにC#を使用する必要があるため、いくつかのコードを蓄積しました。次のコードは、HTMLコードからDOM TreeViewを生成する例です。
//プロセスは再帰的に呼ばれます
// dom_nodeは現在のHTML DOMノードです
// tree_nodeは、現在挿入されているツリーのノードです
private void insertdomnodes(ihtmldomnode parentnode、treenode tree_node)
{
int sibing = 0; //兄弟ノード間の現在のノードの順序は「、」によって分離されます。
if(parentnode.haschildnodes())
{
// level ++;
// pathstring = pathstring + "、" + level;
ihtmldomchildrencollection allchild =(ihtmldomchildrencollection)parentnode.childnodes;
int length = allchild.length;
for(int i = 0; i <length; i ++)
{
文字列instring = pathstring;
instring = instring+"、"+sibing ++;
ihtmldomnode child_node =(ihtmldomnode)allchild.item(i);
treenode tempnode = tree_node.nodes.add(child_node.nodename +"_" +instring);
//文字列tmp =
insertdomnodes(child_node、tempnode);
pathstring = instring;
}
}
}
private void evipsbrowser_documentcomplete(object sender、axshdocvw.dwebbrowserevents2_documentcompleteevent e)
{
pathstring = "0";
レベル= 0;
domtreeview.nodes.clear();
ihtmldocument3 htmldocument =(ihtmldocument3)evipsbrowser.document;
ihtmldomnode rootdomnode =(ihtmldomnode)htmldocument.documentelement;
treenode root = domtreeview.nodes.add( "html"+"_"+pathstring);
insertdomnodes(rootdomnode、root);
}