asp.net 生成xml文件 与 asp生成xml文件
webservice方式,调用接口:
[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;
}
二、asp 生成xml文件
1、写好asp文件后iis部署下即可使用
[vb]
<!-- #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为连接配置主文件
[vb]
<%@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也可以使用
[html]
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webserver>
<directorybrowse enabled="true" />
</system.webserver>
</configuration>