XML C # Operations XML Preliminary (1) Chapter One: New XML file
The following is also the way to create Xml with text <% @ Import namespace= "System.IO"%><% @ Import namespace= "System.Xml"%><% @ Import Namesp Ace= "System.Data"%><script language= "C #" runat= "Server" >public void Page_Load (Object Src,eventargs e) {/** copyright : Copyright by SEM IT department* Edition: Version 0.0.1* file: createxml_2.aspx* use: Create an XML file, use the flow of the way to build * Author: Ouyang Yun @2005- 4-7* e-mail: outrace@soueast-motor.com* Modified: * * String filename;filename = "Users_2.xml"; try {//Use flow to create a new XML file FileStream fs = new FileStream (Server.MapPath ("./files/" +filename), FileMode.CreateNew), FS. Close ();//Add some data streamwriter RW = File.appendtext (Server.MapPath ("./files/" +filename)); RW. WriteLine ("<?xml version=\" 1.0\ "encoding=\" gb2312\ "?>"); 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 (); Reads XML with XML DOM and binds it to the XML control XmlDocument doc = new XmlDocument (); Doc. Load (Server.MapPath ("./files/" +filename)); Xml1. Document = doc; The catch (Exception ex) {Response.Write (ex). message);} finally{}}</script>
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.