Results 1 to 2 of 2

Thread: fill a treeview from an xmlnode's child nodes

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    7

    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..

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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
  •  



Click Here to Expand Forum to Full Width