Asp.net generates xml files and asp generates xml files

Source: Internet
Author: User

1. asp.net generates xml file webservice. Call the interface: [csharp] public XmlDocument List () {XmlDocument doc = new XmlDocument (); StringBuilder sb = new StringBuilder (); IList <CityInfo> list = iCity. infoList (); sb. append ("<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> "); Sb. Append (" <data> "); if (list! = Null & list. count> 0) {foreach (CityInfo item in list) {sb. append (string. format ("<area id = {0} title = {1} alpha = {2} value = {3}/>", item. ID, item. title, item. alpha, item. value) ;}} sb. append ("</data>"); doc. innerXml = sb. toString (); return doc;} II. xml file generated by asp 1. After asp file is written, you can use [vb] Under IIS deployment. <! -- # Include file = "conn. asp" --> <% Response. ContentType = "text/xml" %> <? Xml version = "1.0" encoding = "UTF-8"?> <% Gdtmp = gdtmp & "<strategy>" & chr (13) & chr (10) set rs = server. createobject ("adodb. recordset ") SQL =" select * from tableInfo "set rs = server. createobject ("adodb. recordset ") rs. open SQL, conn12, 1, 1 do while not rs. eof mytime = rs ("mytime") val = rs ("val") preVal = rs ("preVal") amplitude = rs ("Amplitude ") gdtmp = gdtmp & "<item>" & chr (13) & chr (10) gdtmp = gdtmp & "<time> <! [CDATA ["& mytime &"]> </time> "& chr (13) & chr (10) gdtmp = gdtmp &" <val> <! [CDATA ["& val &"]> </val> "& chr (13) & chr (10) gdtmp = gdtmp &" <preVal> <! [CDATA ["& preVal &"]> </preVal> "& chr (13) & chr (10) gdtmp = gdtmp &" <ampltmp> <! [CDATA ["& ldata &"]> </amplr> "& chr (13) & chr (10) gdtmp = gdtmp & "</item>" & chr (13) & chr (10) I = I + 1 rs. movenext loop rs. close set rs = nothing conn12.close set conn12 = nothing gdtmp = gdtmp & "</strategy>" & chr (13) & chr (10) response. write gdtmp %> 2. conn. asp: configure the main file [vb] for connecting to the database <% @ LANGUAGE = "VBSCRIPT" %> <% on error resume next '. Put this line of code in conn. the first line of asp. 'Libor query dim DbServer12, DbName12, DbUserName12, DbPassword12 DbServer12 = "" DbName12 = "" DbUserName12 = "" DbPassword12 = "" connstr12 = "Provider = SQLOLEDB.1; data Source = "& DbServer12 &"; Initial Catalog = "& DbName12 &"; User ID = "& DbUserName12 &"; Password = "& DbPassword12 &"; "Set CONN12 = Server. createObject ("ADODB. connection ") conn12.ConnectionTimeout = 300 conn12.open connstr12 %> 3. If no configuration file is added. config can also Use [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <system. webServer> <directoryBrowse enabled = "true"/> </system. webServer> </configuration>

Related Article

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.