纠结的VBscript
ASP:
<%
dim i,x,xmlDoc
Set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async=false
xmlDoc.load(Server.MapPath("fwz.xml"))
x=xmlDoc.getElementsByTagName("name").length
response.write(xmlDoc.getElementsByTagName("name")(0).childNodes(0).nodeValue)
for i=0 to x
response.write(xmlDoc.getElementsByTagName("name")(i).childNodes(0).nodeValue)
next
%>
fwz.xml:
<?xml version="1.0"?>
<root>
<huiyuan>
<id1><name>nihao</name><password>775859</password></id1>
<id2><name>gsdfg</name><password>sfg</password></id2>
<id_3432><name>3432</name><password>3453453</password></id_3432>
<id_sackee><name>sackee</name><password>1133255</password></id_sackee>
<id_hehe><name>hehe</name><password>5464645</password></id_hehe>
</huiyuan>
</root>
问题:
明明response.write(xmlDoc.getElementsByTagName("name")(0).childNodes(0).nodeValue)都能写出 nihao,
但是response.write(xmlDoc.getElementsByTagName("name")(i).childNodes(0).nodeValue)这行却报错说:
Microsoft VBScript 运行时错误 (0x800A01A8) 缺少对象: 'getElementsByTagName(...)(...)'
[解决办法]
response.write(xmlDoc.getElementsByTagName("name")(0).childNodes(0).nodeValue)
你把这句注释掉再试下。。
[解决办法]
Msxml2.DOMDocument 用XPATH更简单
<%dim i,nodes,xmlDocSet xmlDoc = CreateObject("Msxml2.DOMDocument")xmlDoc.async=falsexmlDoc.load(Server.MapPath("fwz.xml"))Set nodes = xmlDoc.selectNodes("//name")for i=0 to nodes.length-1 response.write nodes(i).textnext%>
[解决办法]
for i=0 to x-1