一、asp.net 生成xml文件
webservice方式,调用接口:
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; }
二、asp 生成xml文件
1、写好asp文件后IIS部署下即可使用
<!-- #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&"<amplitude><![CDATA["&litude&"]]></amplitude>"&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为连接数据库配置主文件
<%@LANGUAGE="VBSCRIPT"%> <% on error resume next '这行代码放到conn.asp的第一行。 'LIBOR 查询 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、如果不部署添加个配置文件web.config也可以使用
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <directoryBrowse enabled="true" /> </system.webServer> </configuration>