Copy Code code as follows:
Using System.Xml;
Initializing an instance of XML
XmlDocument xml=new XmlDocument ();
Import the specified XML file
Xml. Load (path);
Xml. Load (HttpContext.Current.Server.MapPath ("~/file/bookstore.xml"));
Specify a node
XmlNode Root=xml. selectSingleNode ("/root");
Get all direct child nodes under node
XmlNodeList Childlist=root. ChildNodes;
Determine if there are child nodes under this node
Root. HasChildNodes;
Gets a collection of sibling nodes with the same name
XmlNodeList Nodelist=xml. SelectNodes ("/root/news");
Generate a new node
XmlElement Node=xml. CreateElement ("News");
Adds a node under the specified node as its child node
Root. AppendChild (node);
Add a node before a child node under the specified node
Root. InsertBefore (Node,root. Childenodes[i]);
Creates a new property for the specified node and assigns a value
Node. SetAttribute ("id", "11111");
To add a child node to a specified node
Root. AppendChild (node);
Gets the specified property value for the specified node
String Id=node. attributes["id"]. Value;
Gets the text in the specified node
String Content=node. InnerText;
Save XML file
String Path=server.mappath ("~/file/bookstore.xml");
Xml. Save (path);
or Use:xml. Save (HttpContext.Current.Server.MapPath ("~/file/bookstore.xml"));