/// <summary>
/// 解析XML成DATATABLE
/// </summary>
/// <param name="strXMl">xml格式文本</param>
private DataTable parseXML2DataTable(string strXMl)
{
XmlDocument dom = new XmlDocument();
//加载XML文件
dom.LoadXml(strXMl);
DataTable dt = new DataTable();
dt.Columns.Add("Value");
dt.Columns.Add("Text");
//循环读取XML文件内容
foreach (XmlNode node in dom.GetElementsByTagName("DataRight"))
{
DataRow dr = dt.NewRow();
for (int i = 0; i < node.ChildNodes.Count; i++)
{
dr[i] = node.ChildNodes[i].InnerText;
}
dt.Rows.Add(dr);
}
return dt;
}
如何将xml解析成datatable
最新推荐文章于 2018-11-09 13:41:55 发布