大家看看这段asp

为什么生成的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  

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

1. replace "CreateNode" with "CreateElement"

2. remove or comment out this line:
on error resume next
---------------------------------------------------------------

Http://www.w3schools.com
xmldom的学习指南。

Http://www.ChinaOK.net/Examples/
js+xml+dom的一些例子。

你可以下一个xmlsdk看看。
---------------------------------------------------------------

给你一个简单的例子:
Dim a
Set a= server.CreateObject("Microsoft.XMLDOM")
Dim element
a.loadXML "

1<root></root>

" ''loadXML方法,load一个xml字符串
a.documentElement.setAttribute "id", "00001" ''填写根节点属性id='00001'
Set element = a.createElement("Record") ''定义一个element变量
element.setAttribute "name", "yourname" ''增加element的属性name='yourname'
element.Text = "context" ''增加element的内容context
a.documentElement.appendChild element ''把element加到a.documentElement(根节点)的下面
response.write a.xml ''用字符串形式输出a

-------------------------------------------------------------------------------
oneway:我总结了一下,后来修改了代码成功了
1. 用“creatnode”语句也是可以的,但参数要写全,创建element node时,格式如下
childNode=xmldoc.createnode(1,"student","")
具体我是参考MSXML的sdk

2. remove or comment out this line:
on error resume next
在调试asp程序时,如果加上了上述语句确实会掩盖很多错误提示,看上去什么错
误都没有,但事实上程序并没执行完,我当时就犯了这个错误。

Published At
Categories with Web编程
comments powered by Disqus