I got past the node name by using inTreeNode.Text = inXmlNode.InnerText.ToString
This works, however it takes the very top node and edits the name of it to be the contents of every node below it.
Is there a way to skip the very top node?
If inTreeNode.Parent Is Nothing Then
'this is top level. do nothing
Else
inTreeNode.Text = inXmlNode.InnerText.ToString
End If
- Label1.Text = "File Path"
-
Label1.SetBounds(8, 8, 50, 20)
-
TextBox1.Text = Application.StartupPath() & "\Sample.xml"
-
Dim filename As String = Application.StartupPath() & "\Sample.xml"
-
TextBox1.SetBounds(64, 8, 256, 20)
-
Button1.Text = "Populate the TreeView with XML"
-
Button1.SetBounds(8, 40, 200, 20)
-
Me.Text = "TreeView control from XML"
-
Me.Width = 336
-
Me.Height = 368
-
TreeView1.SetBounds(8, 72, 312, 264)
-
-
Dim xmldoc As New XmlDataDocument()
-
Dim xmlnode As XmlNode
-
Dim fs As New FileStream("Sample.xml", FileMode.Open, FileAccess.Read)
-
xmldoc.Load(fs)
-
xmlnode = xmldoc.ChildNodes(1)
-
TreeView1.Nodes.Clear()
-
TreeView1.Nodes.Add(New TreeNode(xmldoc.DocumentElement.Name))
-
Dim tNode As TreeNode
-
tNode = TreeView1.Nodes(0)
-
AddNode(xmlnode, tNode)
-
End Sub
-
-
Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
-
Dim xNode As XmlNode
-
Dim tNode As TreeNode
-
Dim nodeList As XmlNodeList
-
-
Dim i As Integer
-
Dim j As Integer = 0
-
If inXmlNode.HasChildNodes Then
-
nodeList = inXmlNode.ChildNodes
-
For i = 0 To nodeList.Count - 1
-
xNode = inXmlNode.ChildNodes(i)
-
inTreeNode.Nodes.Add(New TreeNode(xNode.Name))
-
inTreeNode.Text = inXmlNode.InnerText.ToString
-
tNode = inTreeNode.Nodes(i)
-
AddNode(xNode, tNode)
-
Next
-
Else
-
inTreeNode.Text = " "
-
End If
-
End Sub