|
以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XML基础 』 (http://bbs.xml.org.cn/list.asp?boardid=1) ---- [转帖]教你一招:如何用Asp动态生成xml文件 (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=15886) |
|
-- 作者:Qr -- 发布时间:3/21/2005 11:30:00 PM -- [转帖]教你一招:如何用Asp动态生成xml文件 相关代码如下: Function ReplaceChar ( FstrSource ) dim strRet if IsNull(FstrSource) then &n bsp; FstrSource = "" end if strRet = Replace ( FstrSource , "&" , "&" ) strRet = Replace ( strRet , "<" , "<" ) strRet = Replace ( strRet , ">" , ">" ) strRet = Replace ( strRet , """" , """ ) strRet = Replace ( strRet , "'" , "'" ) ReplaceChar = strRet End Function function RstToXML (FrstRst, FstrRstName) dim strSpace 'space string behand of element dim intLevel 'level of the element dim strXML 'the return string(xml string) dim intRstField dim strShortDate 'document level intLevel = 0 strSpace = space (intLevel * 2) if Len(FstrRstName)>0 then strXML=strSpace & "<" & FstrRstName & ">" & vbCR intLevel = intLevel + 1 strSpace = space(intLevel*2) end if if FrstRst.EOF then strXML = strXML&strSpace & "<Record" for nCount=0 to FrstRst.Fields.Count-1 strXML = strXML & space(1)&FrstRst.Fields(nCount).Name&"=''" next strXML = strXML & "/>" &vbCR if Len(FstrRstName)>0 then strXML=strXML&strSpace & "</" & FstrRstName & ">" & vbCR end if RstToXML=strXML exit function end if ' now move in one level intLevel = intLevel + 1 strSpace = space (intLevel * 2 ) ' loop through the records dim strTemp FrstRst.MoveFirst do while not FrstRst.EOF strTemp = "" 'loop through the fields 'strXML = strXML & strSpace & "<Record" for each objField in FrstRst.Fields 'set objField = FrstRst.Fields(intRstField) strTemp = strTemp & space (1) & objField.Name & "=" strTemp = strTemp & """" & ReplaceChar(objField.Value) & """" end if next strXML = strXML & "<Record "&strTemp& "/>" & vbCR FrstRst.MoveNext loop intLevel=intLevel-1 strSpace=space(intLevel * 2) if Len(FstrRstName)>0 then strXML = strXML & strSpace & "</" & FstrRstName & ">" & vbCR end if RstToXML = strXML end function getInfo.asp 相关代码如下: <?xml version="1.0" encoding="gb2312"?> <root> <% set conn = server.CreateOb ject("ADODB.Connection") conn.Open "FILEDSN=test.dsn" set facultyRst = conn.Execute("select * from faculty") or <% |
|
-- 作者:appleparty -- 发布时间:3/22/2005 11:22:00 AM -- 是两个代码吗?上下两个代码有什么关系,请老大说明一点好吗 |
|
-- 作者:luoknd -- 发布时间:3/23/2005 5:27:00 PM -- 学习中.................... |
|
-- 作者:suming -- 发布时间:5/13/2005 2:28:00 PM -- 这样就行啦?1!哈哈。 |
|
-- 作者:寒冰2005 -- 发布时间:5/24/2005 10:23:00 AM -- 不会用啊 怎么弄的呀 |
|
-- 作者:killl -- 发布时间:5/24/2005 1:40:00 PM -- 老大,给电详细的说明亚 |
|
-- 作者:jamen -- 发布时间:10/4/2005 10:48:00 PM -- 就是,老大,给点注释嘛 |
|
-- 作者:callect -- 发布时间:4/1/2006 10:29:00 AM -- 有谁用的这个代码了吗?一大堆错,像这种不负责任的转贴还加精,真不可理解 |
|
-- 作者:xot123 -- 发布时间:4/25/2006 8:01:00 PM -- 垃圾也在这里冒充高手,半桶水丁冬响,只能说现在的人太虚荣了 |
|
-- 作者:Qr -- 发布时间:4/26/2006 1:09:00 PM -- 实在抱歉,贴子是本人转的。具体代码正确与否不是关键,这里探究的是实现过程的方法。如果你不理解代码所做的事,直接代码COPY来使用,不错才怪。这样的例子不少见,很多网友拿了本教材,就以为金玉良言,照抄运行结果错误。还有些网友,连调试代码都不会,或者根本上就懒得调试,纯粹依赖别人。还有的,没人回贴甚至还恶语相向,进行人身攻击,那叫什么,可怜虫...呜呼哀哉! |
|
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
78.125ms |