Share sample code for creating root nodes and child nodes in xml

Source: Internet
Author: User
Declare, create, create a root node, add a child node of Books, and finally save the document (if the file already exists, update it; if not, create the file ), none of you can understand the definition, creation, and creation of the root node, and addition of the Books sub-node to save the document (if the file already exists, update it; if not, this file is created ).

The code is as follows:

Protected void button#click (object sender, EventArgs e) // create xml {// declare XmlDocument x = new XmlDocument (); // create XmlDeclaration xd = x. createXmlDeclaration ("1.0", "GB2312", null); x. appendChild (xd); // create the root node XmlElement = x. createElement ("Books"); x. appendChild (element); // add the child node XmlNode book of Books = x. createElement ("Book"); // add the XmlElement bookname = x. createElement ("name"); bookname. innerText = "three kingdoms"; // add it to the book on the node step by step. appendChild (bookname); element. appendChild (book); x. appendChild (element); // save the document (if the file already exists, update it; if not, create the file) x. save (@ "F:/Books. xml ");}

The above is the sample code sharing for creating root nodes and subnodes in xml. 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.