VB6 incoming XML data to the TreeView control

Source: Internet
Author: User
Tags add contains end xml parser
treeview|xml| Control | data

Because XML documents are in a tree-structured format, they are usually displayed using the TreeView control. The following code snippet explains how to pass an XML document to a TreeView control in Visual Basic 6.

First, create a new visual Basic 6 project with a form, then add a TreeView control to the form and add a reference to the Microsoft XML parser.

Next, add the following code to the Form_Load event:


Private Sub Form_Load ()
Dim Objdom as DOMDocument

Set objdom = New DOMDocument
Call Objdom.loadxml (_
" ")

Call AddNode (objdom.documentelement, nothing)

Set objdom = Nothing
End Sub

The above code builds and passes in the XML, and then calls the AddNode method. It contains two variables: The added XML node, the TreeView node added. The AddNode method is invoked for the first time, and "Nothing" is passed to the TreeNode variable.

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

First, the AddNode method adds a new node to the tree control, and then passes the node's text to the XML node's name. If the XML node contains child nodes, the AddNode method adds the child nodes progressively until all child nodes are passed.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.