Để đọc file xml:
protected void btnReader_Click(object sender, EventArgs e)
{
string myXMLfile = @"E:\jlpt3.xml";
DataSet ds = new DataSet();
// Create new FileStream with which to read the schema.
System.IO.FileStream fsReadXml = new System.IO.FileStream
(myXMLfile, System.IO.FileMode.Open);
ds.ReadXml(fsReadXml);
GridView1.DataSource = ds;
GridView1.DataBind();
fsReadXml.Close();
}
Để sắp xếp file xml
protected void btnArrange_Click(object sender, EventArgs e)
{
string myXMLfile = @"E:\jlpt3.xml";
DataSet ds = new DataSet();
System.IO.FileStream fsReadXml = new System.IO.FileStream
(myXMLfile, System.IO.FileMode.Open);
ds.ReadXml(fsReadXml);
DataView dv = new DataView(ds.Tables[0]);
DataTable dt = dv.Table;
dt.Columns[0].ColumnName = "kana";
dt.Columns[1].ColumnName = "kanji";
dt.Columns[2].ColumnName = "type";
dt.Columns[3].ColumnName = "english";
dv.Sort = dt.Columns[3].ColumnName;
// append "DESC" to the sort field name in order to
// sort descending
dv.Sort += " DESC";
GridView1.DataSource = dv;
GridView1.DataBind();
fsReadXml.Close();
}
Nguồn bài viết:
DOTNET.VN