C # to XML operations: Building XML (1)

Source: Internet
Author: User
XML C # Operations XML Preliminary (1) Chapter One: New XML file
There are different ways to create a new XML file, and here are three ways to <% @ Import namespace= "System.IO"%><script language= "C #" runat= "Server" >public void Page_Load (Object Src,eventargs e) {/** copyrights: Copyright by SEM IT department* version of: Version 0.0.1* file: createxml_1.a spx* Purpose: To create an XML file we can create a new XML file by creating a text literal * Author: Ouyang Yun @2005-4-7* mailbox: outrace@soueast-motor.com* Modify: * * String Filename;filename = "Users_1.xml";//Set up Streamwrite, please note set up your own file directory here StreamWriter rw = file.createtext (Server.MapPath (" .") + "\\files\\" +filename)//Use WriteLine to write to content RW. WriteLine ("<?xml version=\" 1.0\ "encoding=\" gb2312\ "?>"); rw. WriteLine ("<users>"); rw. WriteLine ("<user id=\" 1\ ">"); rw. WriteLine ("<userName>outrace</userName>"); rw. WriteLine ("<userPass>ouyang</userPass>"); rw. WriteLine ("</user>"); rw. WriteLine ("<user id=\" 2\ ">"); rw. WriteLine ("<userName>trace</userName>"); rw. WriteLine ("<userPass>ouyang</userPass>"); rw. WriteLine ("</user>"); rw. WritEline ("</users>");//Writes the contents of the buffer to the file RW. Flush ();//Close RW object RW. Close ();//Open Text file StreamReader sr = File.OpenText (Server.MapPath (".") + "\\files\\" +filename)///When using character connection, C # recommends using StringBuilder instead of "+" characters to connect//I heard it would be a lot quicker, but not tested StringBuilder output = new StringBuilder (); String Rl;while (RL=SR. ReadLine ())!=null) {output. Append (rl+ "<br>");} Lblfile.text = output. ToString (); Sr. Close ();} </script>

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.