Realization of data exchange function of XML file as middleware in asp.net (c#,sql2000)

Source: Internet
Author: User

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>");
}

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.