View Code
 1         /// <summary>
 2         /// 将标引信息写入xml文件
 3         /// </summary>
 4         /// <param name="fileName">视频文件名</param>
 5         /// <param name="filePath">视频问价路径</param>
 6         /// <param name="index">标引信息实体</param>
 7         public void AddIndexInfo(string fileName, string filePath,IndexInfo index)
 8         {
 9             //获取xml文件名
10             string xmlName = filePath.Substring(0, filePath.LastIndexOf('\\')) + "\\" + fileName.Substring(0, fileName.LastIndexOf('.')) + ".xml";
11 
12             //创建xml文档对象
13             XmlDocument xmlDoc = new XmlDocument();
14 
15             try
16             {
17                 //装载XML文件
18                 xmlDoc.Load(xmlName);
19 
20                 //得到indexs元素
21                 XmlNode root = xmlDoc.SelectSingleNode("indexs");
22                 //创建一个index元素
23                 XmlElement indexElement = xmlDoc.CreateElement("index");
24 
25                 //创建一个time元素
26                 XmlElement time = xmlDoc.CreateElement("time");
27                 time.InnerText = index.Time;
28                 //添加子元素
29                 indexElement.AppendChild(time);
30 
31                 //创建一个content元素
32                 XmlElement content = xmlDoc.CreateElement("content");
33                 content.InnerText = index.Content;
34                 //添加子元素 
35                 indexElement.AppendChild(content);
36 
37                 //最后将index元素添加到根元素中
38                 root.AppendChild(indexElement);
39                 //重新保存到xml文件中
40                 xmlDoc.Save(xmlName);
41             }
42             catch (Exception e)
43             {
44                 throw e;
45             }          
46         }

 

posted on 2012-07-12 16:25  捣乃忒  阅读(157)  评论(0)    收藏  举报