Reading a XML file to build a treeview

TyB

Well-known member
Joined
May 14, 2009
Messages
102
Programming Experience
3-5
Hello all,

I used an example to create a XML document like this.

<?xml version="1.0" encoding="utf-8"?>
<Dups>
<Parent Path="C:\Pics\Duo.JPG">
<Child>C:\Pics\DSCN1303.JPG</Child>
</Parent>
<Parent Path="C:\Pics\Homes.JPG">
<Child>C:\Pics\DSCN1295.JPG</Child>
</Parent>
</Dups>

I'm trying to read this into variables that I will use to build a treeview, but for the life of me I cannot seem to get it. I would apperciate any help. This is what I'm trying to do.

dim PartentPath as new List(of String)
dim ChildPath as new List(of String)

ParentPath.add("C:\Pics\Duo.JPG")
ChildPath.add("C:\Pics\DSCN1303.JPG")

Thanks,

Ty
 
[resolved]

I finally was able to get it.

For other users....

Dim xd As New XmlDocument()
xd.Load(System.AppDomain.CurrentDomain.BaseDirectory() & "\xml\dups.xml")

' Find Parent's
Dim nod As XmlNodeList = xd.SelectNodes("/Dups/Parent")

Dim n As XmlNode
' Scroll through the nodes
For Each n In xd.SelectNodes("/Dups/Parent")
'Add parent node to tree.
Dim newNode As TreeNode = New TreeNode(n.Attributes("Path").Value)
TreeView1.Nodes.Add(newNode)
TreeView1.SelectedNode = newNode

For i = 0 To n.ChildNodes.Count - 1
'add children nodes to tree
Dim myNodechild As New TreeNode
myNodechild.Text = n.ChildNodes(i).InnerText
TreeView1.SelectedNode.Nodes.Add(myNodechild)
Next
Next

Thanks,
Ty
 
Back
Top