xml| Data | The database used to generate the corresponding XML file in a company project using the records in the database [primarily to improve access speed], but because of the lack of information at that time, encountered in the development process but the difficulties, fortunately, finally completed the work, I am here at that time one of the functional functions listed, It is in the function of Datong small meaning, I hope that the brothers in the future in the face of this problem is not like I did the same.
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Diagnostics;
Using System.Web;
Using System.Web.Services;
Using System.Xml;
Using System.Data.SqlClient;
Using System.Configuration;
Using System.Text;
Using SYSTEM.XML.XSL;
Using System.IO;
Namespace Admin
{
<summary>
Summary description of the createxml.
</summary>
///
[System.Web.Services.WebService (namespace= "Http://..../admin/createxml.asmx", description= "XML file in the build or more Nova Fan club")]
public class CreateXML:System.Web.Services.WebService
{
Public Createxml ()
{
CodeGen: This call is required by the ASP.net Web service designer
InitializeComponent ();
}
Code generated #region Component Designer
Required by the WEB service designer
Private IContainer components = null;
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
}
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing && components!= null)
{
Components. Dispose ();
}
Base. Dispose (disposing);
}
String sqlstatement= "SELECT * from club where id=" +id. ToString (). Trim ();
SqlConnection myconnection= New SqlConnection (strconn);
SqlDataAdapter mycommand = new SqlDataAdapter (sqlstatement,myconnection);
DataSet myDataSet;
Mycommand.selectcommand.commandtype=commandtype.text;
myDataSet = new DataSet ();
Mycommand.fill (myDataSet, "MyTable");
picxmlwriter.formatting = formatting.indented;
Picxmlwriter.indentation= 6;
Picxmlwriter.namespaces = false;
Picxmlwriter.writestartdocument ();
Picxmlwriter.writedoctype ("document Type", NULL, ". xml", NULL);
Picxmlwriter.writecomment ("Read and write by ID recorded in database");
Picxmlwriter.writeprocessinginstruction ("Xml-stylesheet", "type= ' text/xsl ' href= ')." /.. /xsl/1.xsl ' "); Write the XSL file name for interpretation
Picxmlwriter.writestartelement ("", "Club", "");
foreach (DataRow R in Mydataset.tables[0]. rows)//To remove all rows sequentially
{
Picxmlwriter.writestartelement ("", "Record", "");
foreach (DataColumn c in mydataset.tables[0]. Columns)//Find all column properties of the current record in turn
{
if ((C.caption.tostring ()!= "pic")
{
Picxmlwriter.writestartelement ("", c.caption.tostring (). Trim (), "" "); Write field name
Picxmlwriter.writestring (R[c]. ToString (). Trim ()); Write Data
Picxmlwriter.writeendelement ();
}
Else
{
Picxmlwriter.writestartelement ("", c.caption.tostring (). Trim (), "" ");
string [] pic=r[c]. ToString (). Trim (). Split (' | ');
for (int i=0;i<pic. length;i++)
{
if (pic[i). Trim ()!= "")//Database picture fields are inserted in the format: file name, height, Width | Analogy. such as no.jpg,132,142|
{
Picxmlwriter.writestartelement ("", c.caption.tostring (). Trim () + "s", "");
string [] picstr=pic[i]. Split (', ');
Picxmlwriter.writestartelement ("", "Picstr", "");
Picxmlwriter.writestring (Picstr[0]. Trim (). Trim ());
Picxmlwriter.writeendelement ();
Picxmlwriter.writestartelement ("", "height", "");
Picxmlwriter.writestring (Picstr[1]. Trim (). Trim ());
Picxmlwriter.writeendelement ();
Picxmlwriter.writestartelement ("", "width", "");
Picxmlwriter.writestring (Picstr[1]. Trim (). Trim ());
Picxmlwriter.writeendelement ();
Picxmlwriter.writestartelement ("", "comment", "");
Picxmlwriter.writestring (Pic[++i]. Trim (). Trim ());
Picxmlwriter.writeendelement ();
Picxmlwriter.writeendelement ();
}
Else
{
i++;
}
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.