public bool CreateXML(string strXMLPath, string strXMLName, string[] strNode)
{
try
{
if (!Directory.Exists(strXMLPath))
{
Directory.CreateDirectory(strXMLPath);
}
XmlDocument xmldoc = new XmlDocument();
//创建处理指令
XmlNode nodePI;
nodePI = xmldoc.CreateProcessingInstruction("xml", "version=/"1.0/" encoding=/"gb2312/"");
xmldoc.AppendChild(nodePI);//添加处理指令
//根节点创建
XmlElement rootUser = xmldoc.CreateElement("UserInfo"); //创建根节点
XmlElement rootRecord = xmldoc.CreateElement("Record"); //创建大类
for (int i = 0; i < strNode.Length; i++)
{
//description子节点的创建
XmlElement nodeFiles = xmldoc.CreateElement(strNode[i]); //创建子节点
rootRecord.AppendChild(nodeFiles);//添加子节点
}
rootUser.AppendChild(rootRecord);
xmldoc.AppendChild(rootUser);//添加根节点到文档
xmldoc.Save(strXMLPath + strXMLName);//保存文件
return true;
}
catch (Exception ex)
{
throw ex;
}
}