怎么读取多个XML文件加入dataset

如题所述

//创建XML并添加节点内容
XmlDocument xml = new XmlDocument();
XmlDeclaration Declaration = xml.CreateXmlDeclaration("1.0", "utf-8", null);
XmlNode root = xml.CreateNode(XmlNodeType.Element, "students", null);//创建根节点
xml.AppendChild(root);
int n = 0;
for (int i = 0; i < dgvXML.Rows.Count-1; i++)
{
XmlNode node = xml.CreateNode(XmlNodeType.Element, "student", null);//创建student节点
node.Attributes.Append(xml.CreateAttribute("Id")).InnerText = dgvXML.Rows[i].Cells[0].Value.ToString();
node.Attributes.Append(xml.CreateAttribute("Name")).InnerText = dgvXML.Rows[i].Cells[1].Value.ToString();
node.Attributes.Append(xml.CreateAttribute("Sex")).InnerText = dgvXML.Rows[i].Cells[2].Value.ToString();
node.Attributes.Append(xml.CreateAttribute("Tel")).InnerText = dgvXML.Rows[i].Cells[3].Value.ToString();
node.Attributes.Append(xml.CreateAttribute("Check")).InnerText = "";
root.AppendChild(node);
n = i;
}
//保存文件
xml.InsertBefore(Declaration, xml.DocumentElement);
xml.Save(要保存位置);
Java中一个方法如果定义了返回值,就会在函数的最后加上return语句,用来返回数据,提供给别的方法使用:
温馨提示:答案为网友推荐,仅供参考
相似回答