ASP. net xml operations

Source: Internet
Author: User
Tags net xml

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 ("../7in10. xml "));
// Specify a node
Xmlnode root = xml. selectsinglenode ("/root ");
// Obtain all direct subnodes under a node
Xmlnodelist childlist = root. childnodes;
// Determine whether a subnode exists under the node
Root. haschildnodes;
// Obtain the set of nodes with the same name as the peer node
Xmlnodelist nodelist = xml. selectnodes ("/root/News ");
// Generate a new node
Xmlelement node = xml. createelement ("news ");
// Add a node to a specified node as its subnode
Root. appendchild (node );
// Add the node to a subnode under the specified Node
Root. insertbefore (node, root. childenodes );
// Create a property for the specified node and assign a value to it
Node. setattribute ("ID", "11111 ");
// Add a subnode to a specified Node
Root. appendchild (node );
// Obtain the specified attribute value of a specified Node
String id = node. attributes ["ID"]. value;
// Obtain the text in the specified Node
String content = node. innertext;
// Save the XML file
XML. Save (PATH );
XML. Save (httpcontext. Current. server. mappath ("../7in10. xml "));

Related Article

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.