XMLDOM生成XML文件

为什么生成的xml只有

 1   
 2on error resume next   
 3Dim SQL,RS   
 4  
 5Set RS = Server.CreateObject("ADODB.RecordSet")   
 6Set conn = server.createobject("ADODB.connection")   
 7OpenDBConn conn   
 8  
 9SQL = "SELECT * FROM basic"   
10RS.Open SQL,Conn,1,1   
11RS.MoveFirst   
12  
13Dim xmldoc   
14Set xmldoc = server.CreateObject("Msxml2.DOMDocument.4.0")   
15  
16Dim version   
17Set version = xmldoc.createProcessingInstruction("xml","version='1.0' encoding='GB2312'")   
18xmldoc.appendchild(version)   
19  
20Dim root   
21Set root = xmldoc.CreateNode("root")   
22xmldoc.appendChild(root)   
23  
24while (Not RS.EOF)   
25Set childNode = xmldoc.CreateNode("student")   
26For Each f in rs.Fields   
27Set childnextNode = xmldoc.CreateNode(f.name)   
28childnextNode.Text = f.Value   
29childNode.appendChild(childnextNode)   
30Next   
31RS.MoveNext   
32root.appendChild childNode   
33wend   
34  
35xmldoc.save(Server.Mappath("info.xml"))   
36  

---------------------------------------------------------------

我好像没有看见连接数据库的语句
---------------------------------------------------------------

xml/soap里给你回答了。
这个主要是你对xmldom的操作方法是错误的。
建议你多看看xmldom的sdk

http://www.chinaok.net/examples/
有几个例子。

---------------------------------------------------------------

不可能...至少会存在一个root结点..
去掉这一句:on error resume next看看运行效果

---------------------------------------------------------------

是啊!
调试阶段on error resume next可是大忌啊!!!
---------------------------------------------------------------

是啊!
调试阶段on error resume next可是大忌啊!!!

---------------------------------------------------------------

取数据有错,XMLDOM操作没错。
如果XMLDOM操作有错,则不会有

你把on error resume next注释掉,就可以看到那行有错了。

---------------------------------------------------------------

Dim SQL,RS

Set RS = Server.CreateObject("ADODB.RecordSet")

SQL = "SELECT showname FROM download"
RS.Open SQL,Connys,1,1
RS.MoveFirst

Dim xmldoc
Set xmldoc = server.CreateObject("Msxml2.DOMDocument.4.0")

Dim version
Set version = xmldoc.createProcessingInstruction("xml","version='1.0' encoding='GB2312'")
xmldoc.appendchild(version)

Dim root
Set root = xmldoc.CreateNode(1, "root","")
xmldoc.appendChild(root)

do while (Not RS.EOF)
Set childNode = xmldoc.CreateNode(1,"student","")
For Each f in rs.Fields
Set childnextNode = xmldoc.CreateNode(1,f.name,"")
childnextNode.Text = f.Value
childNode.appendChild(childnextNode)
Next
RS.MoveNext
root.appendChild childNode
loop

xmldoc.save(Server.Mappath("info.xml"))

%>
改了一下,试过了,成功!

Published At
Categories with Web编程
comments powered by Disqus