.net读XML(精简代码)
看到前辈的一段读xml并绑定的代码,写得实在精简,贴上来以供学习。
#region 绑定声音文件
string soundDef = Server.MapPath(Request.ApplicationPath + "/Sound/SoundConfig.xml");
DataSet dsSound = new DataSet();
dsSound.ReadXml(soundDef,System.Data.XmlReadMode.Auto);
DataTable dt = new DataTable();
if(dsSound.Tables.Count > 0)
{
dt = dsSound.Tables[0];
}
if(dt.Rows.Count > 0)
{
DataView dv = dt.DefaultView;
dv.RowFilter = "enalbe <> 'false'";
drpSound.DataSource = dv;
drpSound.DataTextField = "fileName";
drpSound.DataValueField = "fileName";
drpSound.DataBind();
}
#endregion