Vb.Net-Informations.com

  How to create a TreevView from XML




   Categories

    HOME
    VB.NET
    CSHARP

 
   














How to create a TreevView from XML

XML is a self describing language and it gives the data as well as the rules to extract what the data it contains. Reading an XML file means that we are reading the data embedded in tags in an XML file.

xml-tree

In the previous example we already saw how to read an XML file Node wise. Here we are reading XML file as Node and pass the Nodes data to TreeView.


         VB.NET Source Code Download           Print Source Code
         How to create a TreevView from XML - Download
        
VB.Net Tutorial

Imports System.Xml
Imports System.io
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xmldoc As New XmlDataDocument()
        Dim xmlnode As XmlNode
        Dim fs As New FileStream("tree.xml", FileMode.Open, FileAccess.Read)
        xmldoc.Load(fs)
        xmlnode = xmldoc.ChildNodes(1)
        TreeView1.Nodes.Clear()
        TreeView1.Nodes.Add(New TreeNode(xmldoc.DocumentElement.Name))
        Dim tNode As TreeNode
        tNode = TreeView1.Nodes(0)
        AddNode(xmlnode, tNode)
    End Sub

    Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
        Dim xNode As XmlNode
        Dim tNode As TreeNode
        Dim nodeList As XmlNodeList
        Dim i As Integer
        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.InnerText.ToString
        End If
    End Sub
End Class
		

Click here to download the input file tree.xml

VB.NET XML Related Contents
*     How to XML in VB.NET
*     How to create an XML file in VB.NET
*     How to open and read an XML file in VB.NET
*     How to create an XML file in VB.NET using Dataset
*     How to open and read an XML file in VB.NET using Dataset
*     How to create an XML file from SQL in VB.NET
*     How to search in an XML file
*     How to filter data in an XML file
*     How to insert data from xml to database
*     How to create an Excel file from XML
*     How to create an XML file from Excel
*     How to xml to DataGridView
*     How to create Crystal Reports from XML
*     How to serialization in xml
*     How to serialize a .Net Object to XML
*     How to serialize from an XML file to .Net Object

VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial with source code
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved