---
title: "Reading XML using DataSet Class"  
description: "In this article we will discuss how to read and XML File using object of DataSet Class.  Sample XML FileEmployee.xml        7369  SMITH  CLERK  7902"  
author: "Shankar M"  
published: 2013-03-29  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/471/reading-xml-using-dataset-class  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# Reading XML using DataSet Class

In this [article](https://www.mindstick.com/articles/95867/are-you-looking-for-500-credit-score-mortgage-lenders-houston-continue-reading-this-article) we will discuss how to read and [XML File](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp) using object of [DataSet](https://www.mindstick.com/articles/19/dataset) Class.\

##### Sample XML File

[Employee](https://www.mindstick.com/articles/85431/remote-employee-training-tips-tricks).xml

```
<?xml version="1.0" ?>  <EMPLOYEES> <EMP>  <EMPNO>7369</EMPNO>   <ENAME>SMITH</ENAME>   <JOB>CLERK</JOB>   <MGR>7902</MGR>   <HIREDATE>17-DEC-80</HIREDATE>   <SAL>800</SAL>   </EMP> <EMP>  <EMPNO>7499</EMPNO>   <ENAME>ALLEN</ENAME>   <JOB>SALESMAN</JOB>   <MGR>7698</MGR>   <HIREDATE>20-FEB-81</HIREDATE>   <SAL>1600</SAL>   <COMM>300</COMM>   </EMP> <EMP>  <EMPNO>7521</EMPNO>   <ENAME>WARD</ENAME>   <JOB>SALESMAN</JOB>   <MGR>7698</MGR>   <HIREDATE>22-FEB-81</HIREDATE>   <SAL>1250</SAL>   <COMM>500</COMM>   </EMP> <EMP>  <EMPNO>7566</EMPNO>   <ENAME>JONES</ENAME>   <JOB>MANAGER</JOB>   <MGR>7839</MGR>   <HIREDATE>02-APR-81</HIREDATE>   <SAL>2975</SAL>   </EMP> <EMP>  <EMPNO>7654</EMPNO>   <ENAME>MARTIN</ENAME>   <JOB>SALESMAN</JOB>   <MGR>7698</MGR>   <HIREDATE>28-SEP-81</HIREDATE>   <SAL>1250</SAL>   <COMM>1400</COMM>   </EMP>  </EMPLOYEES>
```

##### Snippet to read the XML File

```
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; namespace Reading_XML_Data{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }         private void Form1_Load(object sender, EventArgs e)        {            DataSet ds = new DataSet();            ds.ReadXml(@"D:\Employee.xml");            foreach (DataRow dr in ds.Tables["EMP"].Rows)            {                 MessageBox.Show("Employee ID: " + dr["EMPNO"] +  " Name: " + dr["ENAME"]);            }        }    }}
```

Here,

DataSet ds = new DataSet();

We create an [instance](https://www.mindstick.com/forum/1739/object-reference-is-not-set-to-an-instance-of-an-object-error-in-my-code) of DataSet Class

ds.ReadXml(@"D:\Employee.xml");

The ReadXml [method](https://www.mindstick.com/forum/166/webservice-method) of DataSet class is used to read [XML data](https://www.mindstick.com/forum/149/problem-in-showing-the-xml-data-in-table-form-on-browser) from the File Specified here (Employee.xml) and Load it to the DataSet.

The [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) to the ReadXml method is the [Location](https://www.mindstick.com/blog/11636/relocating-business-or-office-to-another-location) of Employee.xml File

```
foreach (DataRow dr in ds.Tables["EMP"].Rows)            {                 MessageBox.Show("Employee ID: " + dr["EMPNO"] +                  " Name: " + dr["ENAME"]);             }
```

Here we read the rows from the dataset using DataRow class and looping through the rows in the DataSet ds.

Hope this might help you a little.

Thanks for [reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists)

---

Original Source: https://www.mindstick.com/blog/471/reading-xml-using-dataset-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
