1.使用XmlDocument读取XML文件
StringReader stream = null; XmlTextReader reader = null; try { //加载xml XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path+filename); //将xml文件转换为DataSet DataSet xmlDS = new DataSet(); stream = new StringReader(xmlDoc.InnerXml); //从stream装载到XmlTextReader reader = new XmlTextReader(stream); xmlDS.ReadXml(reader); for (int i = 0; i < xmlDS.Tables[0].Rows.Count; i++) { model.ID = xmlDS.Tables[0].Rows[i]["ID"].ToString();//主键ID } }