一、简单介绍 using System.Xml;//初始化一个xml实例XmlDocument xml=new XmlDocument(); //导入指定xml文件xml.Load(path);xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml")); //指定一个节点XmlNode root=xml.SelectSingleNode("/root"); //获取节点下所有直接子节点XmlNodeList childlist=root.ChildNodes; //判断该节点下是否有子节点root.HasChildNodes; //获取同名同级节点集合XmlNodeList nodelist=xml.SelectNodes("/Root/News"); //生成一个新节点XmlElement node=xml.CreateElement("News"); //将节点加到指定节点下,作为其子节点root.AppendChild(node); //将节点加到指定节点下某个子节点前root.InsertBefore(node,root.ChildeNodes[i]); //为指定节点的新建属性并赋值node.SetAttribute("id","11111"); //为指定节点添加子节点root.AppendChild(node); //获取指定节点的指定属性值string id=node.Attributes["id"].Value; //获取指定节点中的文本string content=node.InnerText; //保存XML文件string path=Server.MapPath("~/file/bookstore.xml");xml.Save(path);//or use :xml.Save(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));

评论