bb_hershey
October 16th, 2008, 01:47 PM
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)
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/attachment.php?attachmentid=23532&stc=1
whereas the outcome should be like this.. (using xml writer to generate into treeview)
http://www.codeguru.com/forum/attachment.php?attachmentid=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:
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)
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/attachment.php?attachmentid=23532&stc=1
whereas the outcome should be like this.. (using xml writer to generate into treeview)
http://www.codeguru.com/forum/attachment.php?attachmentid=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: