码迷,mamicode.com
首页 > 其他好文 > 详细

判断XML文件是否寸在

时间:2014-08-27 18:17:48      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:io   ar   文件   sp   on   new   ad   c   app   

  var seg = UserName;                 if (File.Exists(UserName + ".xml"))//c             {                     string Name = "NotRemindBox";

                    XmlDocument xdocs = new XmlDocument();                     xdocs.Load(UserName + ".xml");  //加载xml文件                     //根据ID查找元素                     XmlNode car = xdocs.SelectSingleNode("//NotRemindBox[@Name=\"" + Name + "\"]");                     //   XmlNode node = xdocs.SelectSingleNode("aasman/makeannc/field[@name=‘zone_maps‘]");                     XmlElement Xe = (XmlElement)car;                   //  Xe.SetAttribute("value", "sdfdf");                     //修改值                     Xe.InnerText = "True";                     xdocs.Save(UserName + ".xml");                                   }                 else                 {                     //实例化一个xml文档                     XmlDocument xdoc = new XmlDocument();                     //实例化一个xml文档声明                     XmlDeclaration xdela = xdoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");                     //将声明添加到文档中                     xdoc.AppendChild(xdela);                     //创建元素User                     XmlElement User = xdoc.CreateElement("User");                     //将User元素结点追加到文档中                     xdoc.AppendChild(User);

                    //不再提示NotRemindBoxs                     XmlElement NotRemindBoxs = xdoc.CreateElement("NotRemindBox");                     //NotRemindBoxs结点指定文本内容                     NotRemindBoxs.InnerText = "true";                     User.AppendChild(NotRemindBoxs);

                    //添加属性                     XmlAttribute Name = xdoc.CreateAttribute("Name");                     Name.Value = "DoNotPrompt";                     NotRemindBoxs.Attributes.Append(Name);                     //添加注释                     //     XmlComment xc = xdoc.CreateComment("这部电影很搞笑");                     //   movie2.AppendChild(xc);

                    //保存                     xdoc.Save(UserName + ".xml");                 }              //   string ee = "0013";

             //   XmlDocument xdocs = new XmlDocument();              //   xdocs.Load("Movies2.xml");  //加载xml文件

             //  //根据ID查找元素              //   XmlNode car = xdocs.SelectSingleNode("//Moviez[@No=\"" + ee + "\"]");              ////   XmlNode node = xdocs.SelectSingleNode("aasman/makeannc/field[@name=‘zone_maps‘]");                                     //   XmlElement Xe = (XmlElement)car;                             //    Xe.SetAttribute("value", "sdfdf");              //    Xe.InnerText = "dfgdfg";              //   //car["Moviez"].Value = ee + "1";              //   xdocs.Save("Movies2.xml");

            }

判断XML文件是否寸在

标签:io   ar   文件   sp   on   new   ad   c   app   

原文地址:http://www.cnblogs.com/aersliing/p/3939783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!