ASP.NET将XML数据转换成DataTable
程序员文章站
2022-07-16 18:23:46
...
/// <summary>
/// 获取部门列表
/// </summary>
/// <returns></returns>
public DataTable getRTXDeptmentList()
{
util.RTXAction rtx = new util.RTXAction();
string xmlstr = rtx.GetDepartmentlist();
//GetDepartmentlist()返回XML
//<Departments>
//<Department Name = "测试部门1"/>
//<Department Name = "测试部门2"/>
//</Departments>
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlstr);
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("deptname");
dt.Columns.Add(dc);
for (int i = 0; i < xml.ChildNodes[0].ChildNodes.Count; i++)
{
DataRow dr = dt.NewRow();
dr["deptname"] = xml.ChildNodes[0].ChildNodes[i].Attributes["Name"].Value;
dt.Rows.Add(dr);
}
return dt;
}
/// 获取部门列表
/// </summary>
/// <returns></returns>
public DataTable getRTXDeptmentList()
{
util.RTXAction rtx = new util.RTXAction();
string xmlstr = rtx.GetDepartmentlist();
//GetDepartmentlist()返回XML
//<Departments>
//<Department Name = "测试部门1"/>
//<Department Name = "测试部门2"/>
//</Departments>
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlstr);
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("deptname");
dt.Columns.Add(dc);
for (int i = 0; i < xml.ChildNodes[0].ChildNodes.Count; i++)
{
DataRow dr = dt.NewRow();
dr["deptname"] = xml.ChildNodes[0].ChildNodes[i].Attributes["Name"].Value;
dt.Rows.Add(dr);
}
return dt;
}
上一篇: jquery.dataTable.js 使用详解 一、基础配置
下一篇: 数据归一化