XML and ASP.Net- Read an XML document into dataset

In this article we will learn how to read an XML file directly into dataset by using readxml() method of the Dataset class.
Suppose we have an XML file like this


Now we have to create a dataset and show in the datagrid control, like see below:

You can see below that in the page_Load, an instance of the dataset is created with name dsmain. We use the ReadXml() method is called to read employee.xml file. and in the last this dataset is bound to the datagrid control.

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default3.aspx.vb" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<script runat="server">
    Sub Page_Load()
        Dim dsmain As New DataSet
        dsmain.ReadXml(MapPath("XML file\Employee.xml"))
        DataGrid1.DataSource = dsmain
    End Sub
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <div><asp:DataGrid ID="DataGrid1" runat="server">