CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2008
    Posts
    1

    Populating TreeView with XML using VB.. HOW?

    Hi there.. i've been cracking my head... its for my assignment.. the lecturer's crazy man.. giving us a task that she never even taught us at class..

    anyway i really hope the sifus out there can help me to debug... it...

    here are the codes

    (the nearest one that managed to program)

    Code:
    Imports System.Xml
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Initialize the controls and the form.
            Label1.Text = "File Path"
            Label1.SetBounds(8, 8, 50, 20)
            TextBox1.Text = "......\My Received Files\xml1.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)
        End Sub
    
    
        Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim tNode As TreeNode
            Try
                Dim reader As XmlTextReader = New XmlTextReader(".....\My Received Files\xml1.xml")
                reader.WhitespaceHandling = WhitespaceHandling.Significant
                TreeView1.Nodes.Clear()
                Dim i, n As Integer
                n = 0
                While reader.Read()
                    TreeView1.Nodes.Add(New TreeNode(reader.Name))
    
                    If reader.IsStartElement Then
                        tNode = TreeView1.Nodes(0)
                        tNode.Nodes.Add(New TreeNode(reader.Name))
                    End If
    
                    If reader.HasAttributes Then
                        tNode = TreeView1.Nodes(n)
                        For i = 0 To reader.AttributeCount - 1
                            tNode.Nodes.Add(New TreeNode(reader.GetAttribute(i)))
                        Next
                    End If
                    n += 1
                End While
                TreeView1.ExpandAll()
            Catch xmlEx As XmlException
                MessageBox.Show(xmlEx.Message)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
      
    End Class
    And this is what I got:
    http://www.codeguru.com/forum/attach...id=23532&stc=1

    whereas the outcome should be like this.. (using xml writer to generate into treeview)
    http://www.codeguru.com/forum/attach...id=23533&stc=1

    that's a HUGE difference man... I also why in VB.. they'll also read all the tags.. aiks.. :stars: :stars:

    :help: :help: :help: plz... besides this.. got to capture them and store them into oracle database also.. wow.. this lecturer is killing us...


    THANKS ALOT FOR HELPING TO DEBUG.. REALLY APPRECIATE U GUYS ALOT IN ADVANCE!! :clap: :clap:
    Attached Images Attached Images

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Populating TreeView with XML using VB.. HOW?

    Why not pay more attention in class ¿

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Populating TreeView with XML using VB.. HOW?

    Just drop the class and take it again next semester, and do all the assignments as you get them. I doubt they assigned the program to generate XML and also load into Oracle on the first day...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured