. Net simple methods and instructions for xml operations. if you need a friend, please refer to the simple methods and instructions for sharing. net xml operations. if you need a friend, please refer
The code is as follows:
Using System. xml; // Initialize an xml instance 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"); // Obtain all direct subnodes under the node XmlNodeList childlist = root. childNodes; // determines whether a subnode root exists under the node. hasChildNodes; // obtains the XmlNodeList nodelist = xml. selectNodes ("/Root/News"); // generate a new node XmlElement node = xml. createElement ("News"); // add the node to the specified node as its root node. appendChild (node); // add the node to the root before a subnode under the specified node. insertBefore (node, root. childeNodes [I]); // creates a new attribute for the specified node and assigns a value to the node. setA Ttribute ("id", "11111"); // add the sub-node root for the specified node. appendChild (node); // Obtain the specified attribute value of the specified node string id = node. attributes ["id"]. value; // Obtain the text string content = node in the specified node. innerText; // Save the XML file string path = Server. mapPath ("~ /File/bookstore. xml "); xml. Save (path); // or use: xml. Save (HttpContext. Current. Server. MapPath ("~ /File/bookstore. xml "));
The above is a simple method and description for sharing. net xml operations. For more information, see other related articles in the first PHP community!