1)The .net framework provides the
Dataset object which can handle data from variety of sources like
SQL, XML etc.
2)The
DataSet has a
ReadXML() method which is used to read data from an
XML file.
Code for binding XML data in DataGrid:
Code: using System;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strXMLFile = MapPath("products.xml");
lblXMLFileName.Text = strXMLFile;
DataSet objDataSet = new DataSet();
objDataSet.ReadXml(strXMLFile);
dgServers.DataSource = objDataSet.Tables[0].DefaultView;
dgServers.DataBind();
}
}
Xml file products.xml,
Code: <ProductList>
<Products>
<ProductId>1</ProductId>
<ProductName>Rice</ProductName>
<Rate>27</Rate>
</Products>
<Products>
<ProductId>2</ProductId>
<ProductName>Wheat</ProductName>
<Rate>20</Rate>
</Products>
</ProductList>
This is a simple example .