How to read XML file with multiple tables to a dataset in ASP.net
XML File:"Test.xml"
<?xml version="1.0" encoding="utf-8" ?>
<root>
<scm1>
<table>
<clm1>abc</clm1>
<clm2>1</clm2>
</table>
<table>
<clm1>xyz</clm1>
<clm2>2</clm2>
</table>
<table>
<clm1>pqr</clm1>
<clm2>3</clm2>
</table>
</scm1>
<scm2>
<table2>
<clm1>ijk</clm1>
<clm2>4</clm2>
</table2>
<table2>
<clm1>lmn</clm1>
<clm2>5</clm2>
</table2>
</scm2>
</root>
...............................................................................................................
C#:
using System.Data;
.......................................................
DataSet ds = new DataSet();
ds = new DataSet();
ds.ReadXml(MapPath("Test.xml"));
GridView1.DataSource = ds.Relations[0].ChildTable;
GridView1.DataBind();
GridView2.DataSource = ds.Relations[1].ChildTable;
GridView2.DataBind();
Output:
XML File:"Test.xml"
<?xml version="1.0" encoding="utf-8" ?>
<root>
<scm1>
<table>
<clm1>abc</clm1>
<clm2>1</clm2>
</table>
<table>
<clm1>xyz</clm1>
<clm2>2</clm2>
</table>
<table>
<clm1>pqr</clm1>
<clm2>3</clm2>
</table>
</scm1>
<scm2>
<table2>
<clm1>ijk</clm1>
<clm2>4</clm2>
</table2>
<table2>
<clm1>lmn</clm1>
<clm2>5</clm2>
</table2>
</scm2>
</root>
...............................................................................................................
C#:
using System.Data;
.......................................................
DataSet ds = new DataSet();
ds = new DataSet();
ds.ReadXml(MapPath("Test.xml"));
GridView1.DataSource = ds.Relations[0].ChildTable;
GridView1.DataBind();
GridView2.DataSource = ds.Relations[1].ChildTable;
GridView2.DataBind();
Output:
No comments:
Post a Comment