---
title: "Bind XML file in Tree View control using C#"  
description: "In this blog I am trying to explain how to bind the XML file in tree view control.XMLXML is a self describing language and it provides data as well as"  
author: "Vijay Shukla"  
published: 2013-06-17  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/540/bind-xml-file-in-tree-view-control-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Bind XML file in Tree View control using C#

In this blog I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) how to bind the [XML file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp) in tree view control.

##### XML

XML is a self describing [language](https://www.mindstick.com/startup/28/preply-the-fast-growing-platform-transforming-language-learning) and it provides data [as well as](https://www.mindstick.com/interview/2481/can-you-write-a-java-class-that-could-be-used-both-as-an-applet-as-well-as-an-application) the rules to [extract](https://www.mindstick.com/forum/12883/how-to-extract-sub-string-between-two-string-pattern-using-javascript-jquery) what the data it contains.

Steps for creating this demo.

1. Open [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2010.

2. Create new [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) with appropriate name.

3. [Drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) a tree view in form.

4. Write below code in you editor.

```
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Xml;using System.IO;namespace MinimizDemo{
    public partial class Form3 : Form    {
        public Form3()        {            InitializeComponent();
        }
        private void Form3_Load(object sender, EventArgs e)        {            XmlDataDocument xmldoc = new XmlDataDocument();            XmlNode xmlnode;            FileStream fs = new FileStream(@"D:\Vijay\2013\June\14-06-2013 (Friday)\Demo\Windows\MinimizDemo\MinimizDemo\tree.xml", FileMode.Open, FileAccess.Read);
            xmldoc.Load(fs);            xmlnode = xmldoc.ChildNodes[1];
            treeView1.Nodes.Clear();            treeView1.Nodes.Add(new TreeNode(xmldoc.DocumentElement.Name));
            TreeNode tNode;            tNode = treeView1.Nodes[0];
            AddNode(xmlnode, tNode);        }        private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
        {            XmlNode xNode;            TreeNode tNode;            XmlNodeList nodeList;            int i = 0;            if (inXmlNode.HasChildNodes)            {                nodeList = inXmlNode.ChildNodes;                for (i = 0; i <= nodeList.Count - 1; i++)                {                    xNode = inXmlNode.ChildNodes[i];                    inTreeNode.Nodes.Add(new TreeNode(xNode.Name));                    tNode = inTreeNode.Nodes[i];                    AddNode(xNode, tNode);                }
            }
            else            {                inTreeNode.Text = inXmlNode.InnerText.ToString();
            }        }    }
}
```

##### Output: -

![Bind XML file in Tree View control using C#](https://www.mindstick.com/blogs/e7c180ee-130a-4c7e-acbf-d2b68116577f/images/b4c12982-a342-497c-8be7-75fded318a61.png)

Note: - I got book.xml file from [this link](http://msdn.microsoft.com/en-us/library/windows/desktop/ms762271(v=vs.85).aspx)

---

Original Source: https://www.mindstick.com/blog/540/bind-xml-file-in-tree-view-control-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
