1 /// <summary>
2 /// 创建xml文件
3 /// </summary>
4 /// <param name="fileName">文件名</param>
5 /// <param name="filePath">文件路径</param>
6 public void CreateXML(string fileName, string filePath)
7 {
8 //首先要创建一个空的XML文档
9 XmlDocument xml = new XmlDocument();
10 try
11 {
12 //在XML的文档的最头部加入XML的声明段落
13 XmlNode node = xml.CreateNode(XmlNodeType.XmlDeclaration, "", "");
14 xml.AppendChild(node);
15
16 //添加根元素
17 XmlElement root = xml.CreateElement("indexs");
18 xml.AppendChild(root);
19
20 //获取xml文件路径
21 string xmlName = filePath.Substring(0, filePath.LastIndexOf('\\')) + "\\" + fileName.Substring(0, fileName.LastIndexOf('.')) + ".xml";
22
23 //保存文件路径
24 xml.Save(xmlName);
25 }
26 catch (Exception e)
27 {
28 throw e;
29 }
30 }