Private Sub Form_Load() Dim objDOM As DOMDocument Set objDOM = New DOMDocument Call objDOM.loadXML( _ "<Doc><Node1></Node1><Node2><ChildNode/></Node2></Doc>") Call AddNode(objDOM.documentElement, Nothing) Set objDOM = Nothing End Sub |
Private Sub AddNode(ByRefXMLNode As IXMLDOMNode, ByRefTreeNode As Node) Dim objNode As Node Dim xmlNodeList As IXMLDOMNodeList Dim lngNodeIndex As Long On Error GoTo ERR_HANDLER If TreeNode Is Nothing Then Set objNode = TreeView1.Nodes.Add Else Set objNode = TreeView1.Nodes.Add(TreeNode, tvwChild) End If objNode.Text = XMLNode.nodeName objNode.Expanded = True == Add child nodes Set xmlNodeList = XMLNode.childNodes For lngNodeIndex = 0 To xmlNodeList.length - 1 Call AddNode(xmlNodeList.Item(lngNodeIndex), objNode) Next lngNodeIndex ERR_HANDLER: If Err.Number <> 0 Then MsgBoxErr.Description End If End Sub |