|
-
May 4th, 2003, 02:33 PM
#1
Thread Starter
New Member
fill a treeview from an xmlnode's child nodes
hey all...
ok, new challenge (for me anyway ).
I have an xml file that's built dynamically and I wanna pull out a specific child node from the root and use specific child nodes from it for a treeview..
example XML:
<Root>
<bookMarks>
<bookMarkFolder Name="My Bookmarks">
<bookMark Name="BM1" URL="URL1" userName="user1" Password="pass1" />
<bookMark Name="BM2" URL="URL2" userName="user2" Password="pass2" />
<bookMarkFolder Name="child bookmark">
<bookMark Name="BM3" URL="URL3" userName="user3" Password="pass3" />
</bookMarkFolder>
<bookMarkFolder Name="blah">
<bookMark Name="BM4" URL="URL4" userName="user4" Password="pass4" />
</bookMarkFolder>
</bookMarkFolder>
</bookMarks>
</Root>
ok, so I wanna nab out all the bookMarkFolder elements and use just those in the treeview...
I've tried so many things now that I don't even wanna show my code, kinda embarrasing
Cheers for ANY idea's anyone has..
-
May 4th, 2003, 05:06 PM
#2
PowerPoster
I just wrote this in C#, so if you need help converting it to VB.NET, let me know. Also, you will need to import the System.Xml namespace and make sure the file/path is correct on your machine.
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
TreeNode root = treeView1.Nodes.Add("BookMarks");
XmlDocument source = new XmlDocument();
source.Load("../../settings.xml");
XmlNodeList xmlFolders = source.DocumentElement.SelectNodes("bookMarks/bookMarkFolder");
foreach (XmlNode node in xmlFolders) {
root.Nodes.Add(new TreeNode(node.Attributes.GetNamedItem("name").Value));
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|