protected DataTable bind()
{
string xmlData =
"<?xml version="1.0" encoding="utf-8"
?><DocumentElement><Node><name>aaa</name><value>1</value></Node><Node><name>bbb</name><value>0</value></Node></DocumentElement>";
//定义DataTable结构
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("name", typeof(string)));
dt.Columns.Add(new DataColumn("value", typeof(int)));
//加载XML数据,也可XElement.Load("文件名")
var xdoc = XElement.Parse(xmlData);
var m = (from mod in xdoc.Elements("Node")
select new
{
//给DataTabel添加数据行
a = dt.Rows.Add(new[] { mod.Element("name").Value, mod.Element("value").Value })
}).ToList();
return dt;
}
http://bbs.csdn.net/topics/370227271