|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
因为ASP脚本语言非常简单,因此其代码也简单易懂,结合HTML代码,可快速地完成网站的应用程序。还无法完全实现一些企业级的功能:完全的集群、负载均横。xml|静态|天生xml相干代码以下:
FunctionReplaceChar(FstrSource)
dimstrRet
ifIsNull(FstrSource)then
FstrSource=""
endif
strRet=Replace(FstrSource,"&","&")
strRet=Replace(strRet,"<","<")
strRet=Replace(strRet,">",">")
strRet=Replace(strRet,"""",""")
strRet=Replace(strRet,"","")
ReplaceChar=strRet
EndFunction
functionRstToXML(FrstRst,FstrRstName)
dimstrSpacespacestringbehandofelement
dimintLevelleveloftheelement
dimstrXMLthereturnstring(xmlstring)
dimintRstField
dimstrShortDate
documentlevel
intLevel=0
strSpace=space(intLevel*2)
ifLen(FstrRstName)>0then
strXML=strSpace&"<"&FstrRstName&">"&vbCR
intLevel=intLevel+1
strSpace=space(intLevel*2)
endif
ifFrstRst.EOFthen
strXML=strXML&strSpace&"<Record"
fornCount=0toFrstRst.Fields.Count-1
strXML=strXML&space(1)&FrstRst.Fields(nCount).Name&"="
next
strXML=strXML&"/>"&vbCR
ifLen(FstrRstName)>0then
strXML=strXML&strSpace&"</"&FstrRstName&">"&vbCR
endif
RstToXML=strXML
exitfunction
endif
nowmoveinonelevel
intLevel=intLevel+1
strSpace=space(intLevel*2)
loopthroughtherecords
dimstrTemp
FrstRst.MoveFirst
dowhilenotFrstRst.EOF
strTemp=""
loopthroughthefields
strXML=strXML&strSpace&"<Record"
foreachobjFieldinFrstRst.Fields
setobjField=FrstRst.Fields(intRstField)
strTemp=strTemp&space(1)&objField.Name&"="
strTemp=strTemp&""""&ReplaceChar(objField.value)&""""
endif
next
strXML=strXML&"<Record"&strTemp&"/>"&vbCR
FrstRst.MoveNext
loop
intLevel=intLevel-1
strSpace=space(intLevel*2)
ifLen(FstrRstName)>0then
strXML=strXML&strSpace&"</"&FstrRstName&">"&vbCR
endif
RstToXML=strXML
endfunction
getInfo.asp
相干代码以下:
<?xmlversion="1.0"encoding="gb2312"?>
<root>
<%
setconn=server.CreateObject("ADODB.Connection")
conn.Open"FILEDSN=test.dsn"setfacultyRst=conn.Execute("select*fromfaculty")
dowhilenotfacultyRst.eof
strFaculty=facultyRst("name")
setclassRst=conn.Execute("selectcount(id)asclasscountfromrecruitclasswhererecruityear="+cstr(year(now))+"andfaculty="+strFaculty+"")
setmaleRst=conn.Execute("selectcount(id)asmalecountfromnewstudentwhererecruityear="+cstr(year(now))+"andfaculty="+strFaculty+"andgender=男")
setfemaleRst=conn.Execute("selectcount(id)asfemalecountfromnewstudentwhererecruityear="+cstr(year(now))+"andfaculty="+strFaculty+"andgender=女")
%>
<newstudentfaculty="<%=strFaculty%>"class="<%=classRst("classcount")%>"male="<%=maleRst("malecount")%>"female="<%=femaleRst("femalecount")%>"/>
<%
facultyRst.MoveNext
loop
%>
</root>
<%
dimstrConn,strSQL,rs,n,sFileName
changetheservername,ifitisremote,changetheUIDandPWDtoyourown
strConn="Provider=SQLOLEDB;Server=localhost;Database=pubs;UID=sa;PWD=;"
strSQL="SELECT*FROMemployee"
setrs=Server.CreateObject("ADODB.Recordset")
rs.openstrSQL,strConn,1,1
sFileName="c: empemployee.xml"
rs.savesFileName,1
rs.close
setrs=nothing
%>
or
<%
Response.ContentType="text/xml"
dimstrConn,strSQL,rs,n,sFileName
changetheservername,ifitisremote,changetheUIDandPWDtoyourown
strConn="Provider=SQLOLEDB;Server=localhost;Database=pubs;UID=sa;PWD=;"
strSQL="SELECT*FROMemployee"
setrs=Server.CreateObject("ADODB.Recordset")
rs.openstrSQL,strConn,1,1
sFileName="c: empemployee.xml"
rs.saveResponse,1
rs.close
setrs=nothing
%>
因为现在数据库都使用标准的SQL语言对数据库进行管理,所以如果是标准SQL语言,两者基本上都可以通用的。SQLServer还有更多的扩展,可以用存储过程,数据库大小无极限限制。 |
|