เนื่องจากเราจำเป็นต้องใช้ C# สำหรับการเขียนโปรแกรมที่เกี่ยวข้องเมื่อเร็ว ๆ นี้เราได้รวบรวมรหัสที่เกี่ยวข้อง รหัสต่อไปนี้คือการเข้าถึง HTML และสร้างรหัสหนังสือ Treeview DOM:
โมฆะส่วนตัว InsertDomNodes (ihtmldomnode parentnode, treenode tree_node)
-
if (parentNode.haschildnodes ())
-
ihtmldomchildrencollection allChild = (ihtmldomChildRencollection) ParentNode.childNodes;
ความยาว int = allChild.length;
สำหรับ (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 ลงใน
โมฆะส่วนตัว Evipsbrowser_Documentcomplete (ผู้ส่งวัตถุ, 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);
-