More XML code

OK… I have some more code for my XML project. It still needs to be modified, but the idea is to create a usable user interface. I think I found this code on MSDN but I cannot really remember. It was a month or two back, and is actually code from netAPRS.


Private Sub LoadTreeViewFromXmlFile(ByVal file_name As _
String, ByVal trv As TreeView)
' Load the XML document.
Dim xml_doc As New XmlDocument
xml_doc.Load(file_name)

' Add the root node's children to the TreeView.
trv.Nodes.Clear()
AddTreeViewChildNodes(trv.Nodes, _
xml_doc.DocumentElement)
End Sub
' Add the children of this XML node
' to this child nodes collection.
Private Sub AddTreeViewChildNodes(ByVal parent_nodes As _
TreeNodeCollection, ByVal xml_node As XmlNode)
For Each child_node As XmlNode In xml_node.ChildNodes
' Make the new TreeView node.
Dim new_node As TreeNode = _
parent_nodes.Add(child_node.Attributes.Item(0).Value)
new_node.Tag = child_node.Attributes.Item(1).Value
AddTreeViewChildNodes(new_node.Nodes, child_node)
If new_node.Nodes.Count = 0 Then _
new_node.EnsureVisible()


' If this is a leaf node, make sure it's visible.
Next child_node
End Sub