Create new asp.net web application.
Add your xml file.Name it : abc.xml
Create new class file name it MyDTO.cs
Now Add new web form to show xml data in grid.
Open Webform html view.
Use below code:
Now open webform.cs file.
Add your xml file.Name it : abc.xml
Create new class file name it MyDTO.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
namespace ReadXML | |
{ | |
public class MyDTO | |
{ | |
public string Date { get; set; } | |
public string DESCRIPTION { get; set; } | |
public string Rev { get; set; } | |
public string With { get; set; } | |
} | |
} |
Now Add new web form to show xml data in grid.
Open Webform html view.
Use below code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ReadXML.WebForm1" %> | |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title></title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Visible="true" | |
AllowSorting="True"> | |
<Columns> | |
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" /> | |
<asp:BoundField DataField="DESCRIPTION" HeaderText="DESCRIPTION" SortExpression="DESCRIPTION" /> | |
<asp:BoundField DataField="REv" HeaderText="Rev" SortExpression="Rev" /> | |
<asp:BoundField DataField="With" HeaderText="With" SortExpression="With" /> | |
</Columns> | |
</asp:GridView> | |
</div> | |
</form> | |
</body> | |
</html> |
Now open webform.cs file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Web; | |
using System.Web.SessionState; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
using System.Web.UI.HtmlControls; | |
using System.Xml; | |
using System.Collections.Generic; | |
namespace ReadXML | |
{ | |
public partial class WebForm1 : System.Web.UI.Page | |
{ | |
ReadXML.TcecDTO oUserInfoDTO = new ReadXML.TcecDTO(); | |
List<ReadXML.TcecDTO> Mylist = new List<ReadXML.TcecDTO>(); | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
GridView1.DataSource = GridLoad(); | |
GridView1.DataBind(); | |
Response.Write(Mylist); | |
} | |
public DataView GridLoad() | |
{ | |
XmlDocument doc = new XmlDocument(); | |
doc.Load(Server.MapPath("abc.xml")); | |
DataTable dt = new DataTable("test"); | |
dt.Columns.Add("Date", typeof(System.String)); | |
dt.Columns.Add("DESCRIPTION", typeof(System.String)); | |
dt.Columns.Add("Rev", typeof(System.String)); | |
dt.Columns.Add("With", typeof(System.String)); | |
DataRow dr; | |
XmlNode root = doc.DocumentElement; | |
int k = root.ChildNodes.Count; | |
for (int j = 0; j < k; j++) | |
{ | |
dr = dt.NewRow(); | |
dr["Date"] = root.ChildNodes[j].Attributes[0].ChildNodes[0].InnerText; | |
dr["DESCRIPTION"] = root.ChildNodes[j].Attributes[1].ChildNodes[0].InnerText; | |
dr["Rev"] = root.ChildNodes[j].Attributes[2].ChildNodes[0].InnerText; | |
dr["With"] = root.ChildNodes[j].Attributes[2].ChildNodes[0].InnerText; | |
dt.Rows.Add(dr); | |
oUserInfoDTO.Date = root.ChildNodes[j].Attributes[0].ChildNodes[0].InnerText; | |
oUserInfoDTO.DESCRIPTION = root.ChildNodes[j].Attributes[1].ChildNodes[0].InnerText; | |
oUserInfoDTO.Rev = root.ChildNodes[j].Attributes[2].ChildNodes[0].InnerText; | |
oUserInfoDTO.With = root.ChildNodes[j].Attributes[2].ChildNodes[0].InnerText; | |
Mylist.Add(oUserInfoDTO); | |
} | |
return dt.DefaultView; | |
} | |
} | |
} |