The statement is described in the program section. The main use of the XmlWriter class for XML file generation.
This is the process by which the relational database generates the corresponding XML file. Because XML is only middleware, schemas or DTDs are ignored.
1 private void Page_Load (object sender, System.EventArgs e)
2 {
3//Place user code here to initialize page
4 The basic information defines
5 string strtablename= "systypes";
6 String strconnection= "Server=suntears;user Id=sa;password =041210;database=webapplication1_db ";
7 String strsql= "SELECT * from" +STRTABLENAME;
8 SqlConnection objconn=new SqlConnection (Strconnection);
9 SqlDataAdapter Objadapter=new SqlDataAdapter (Strsql,objconn); The
DataSet objdset=new DataSet ();
One Objadapter.fill (objdset, "temp");
XmlTextWriter Objxmlwriter;
String Strtemp1=request.physicalapplicationpath;
String strpath=strtemp1+ "Qiming.xml";
15//Initialize XmlWriter. Write XML file with this class
Objxmlwriter=new XmlTextWriter (strpath,null);
17//Create the beginning XML declaration objxmlwriter.writestartdocument ();
19//Create root element xml1
Objxmlwriter.writestartelement ("Xml1");
21//table name is element name, field name is property, and record in table is the value of property
for (int i=0;i<objdset.tables["temp"]. rows.count;i++)
{
Objxmlwriter.writestartelement ("menu");
for (int j=0;j<objdset.t ables["Temp"]. columns.count;j++)
{
27//write Properties
Objxmlwriter.writeattributestring (objdset.tables ["Temp"]. COLUMNS[J]. columnname,objdset.tables["Temp"]. ROWS[I][J]. ToString ());
29}
Objxmlwriter.writeendelement ();
31}
Objxmlwriter.writeendelement ();
Objxmlwriter.writeenddocument ();
34//Closes the file with the Close method, otherwise the file will be locked
Objxmlwriter.close ();
36//Show results on page
Strxmlre Sult;
StreamReader OBJSR = File.OpenText (strpath);
Strxmlresult = Objsr.readtoend ();
Objsr.close ();
Response.Write ("<pre>" + Server.HTMLEncode (strxmlresult) + "<pre>");
}