C # Operation XML Preliminary (2) Chapter 1: New XML File The following is also the way to build XML <% @ Import namespace = "system.io"%>
<% @ Import namespace = "system.xml"%>
<% @ Import namespace = "system.data"%>
Public void Page_Load (Object SRC, Eventargs E)
{
/ *
* Copyright by SEM IT Department
* Version: Version 0.0.1
* Document: CREATEXML_2.ASPX
* Use the way: establish an XML file, establish the way to use the stream
* Author: Ouyang Yuntian @ 2005-4-7
* Mailbox: Outrace@soueast-motor.com
* Repair:
* /
String filename;
FileName = "Users_2.xml";
Try
{
// New XML file in the way using flow
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 / "?>");
Rw.writeLine ("
rw.writeLine ("
Rw.writeLine ("
Rw.writeline ("
rw.writeLine (" user>");
Rw.writeLine ("
RW.Writeline ("
Rw.writeline ("
rw.writeLine (" user>");
Rw.writeLine (" users>");
/ / Write the contents of the buffer into the file
Rw.flush ();
// Turn off the RW object
Rw.close ();
// read XML in XML DOM and bind it with XML control
XmLDocument Doc = New XmLDocument ();
Doc.Load (Server.Mappath ("./ files /" filename); XML1.Document = DOC;
}
Catch (Exception EX)
{
Response.write (ex.Message);
}
Finally
{
}
}
script>
hEAD>