Share Simple methods and descriptions of. net xml operations

Source: Internet
Author: User
Tags net xml
. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.