Reading data from XML File

In my last articles, I have discussed about Reading and Writing data from Excel file to GridView and Saving to SQL Table. This article is about Reading data from XML File. We will use a XML File as our datasource on different ways.

In my last articles, I have discussed about Reading and Writing data from Excel file to GridView and Saving to SQL Table.

Today, I am going to Read data from XML File. XML means Extensible Markup Language. As you know, the complete .NET is based on XML and XML is the most popular and platform independent Schema. Which powers all the Documents, Spreadsheets and other common file formats.

So, lets Read XML File and bind its data in GridView.
We will do this in multiple ways. Basically, Supplying file from Front-End and saved file in server and coded at the time of programming.

To do this, XML File should be declared in structured Node.


One XML File can contain Only one Root Node.
Multiple Tables can be created inside one Node.
Sample Design of XML File with following Table Structure.

Roll Name Maths English Science Social

XML Design with Table Name classXII inside Result node.


You can include multiple tables like below designs.


<Name>Abhaya Kumar</Name>

Design of the ASPX Page.



<!DOCTYPE html>
<html xmlns="">
<head runat="server">
<title>Reading date from XML File</title>
<form id="form1" runat="server">
<h2 style="text-align: center">Reading Data from XML</h2>
<br />
XML File :
<asp:FileUpload ID="FileUpload1" runat="server" /> <br />
<br />
Table Name :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" />
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Style="text-align: center" Width="451px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
<br />
<br />

Code to Bind data at BackEnd.
Namespace Required : System.Data

DataSet ds = new DataSet();
GridView1.DataSource = ds.Tables[0].DefaultView;

Data from XML

I have included an Attachment of Project, which can be downloaded and contains XML Data file, Backend codes for multiple methods, Uploading and Reading file and much more.

Feedback and suggestions are always helpful.

Glad to Be,
John Bhatt
P.Yar.B Complex


  • Source Code (
  • Comments

    No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: