Imports System.Xml
Public Class Form1
Private Sub Form1_Load(ByVal sender As System. Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim dom As New XmlDocument
dom.Load(TextBox1.Text)
TreeView1.Nodes.Clear()
TreeView1.Nodes.Add( New TreeNode (dom.DocumentElement.Name))
Dim tnode As New TreeNode
tnode = TreeView1.Nodes(0)
AddNode(dom.DocumentElement, tnode)
TreeView1.ExpandAll()
Catch
End Try
End Sub
Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
Dim xNode As XmlNode
Dim tNode As New TreeNode
Dim nodeList As XmlNodeList
Dim i As Integer = 0
If inXmlNode.HasChildNodes Then
nodeList = inXmlNode.ChildNodes
For i = 0 To nodeList.Count - 1
xNode = inXmlNode.ChildNodes(i)
inTreeNode.Nodes.Add( New TreeNode (xNode.Name))
tNode = inTreeNode.Nodes(i)
AddNode(xNode, tNode)
Next
Else
inTreeNode.Text = (inXmlNode.OuterXml).Trim()
End If
End Sub
End Class
No comments:
Post a Comment