如何使用vbscript和经典asp在xml中选择SingleNode?
发件人: xml:如何使用vbscript和经典asp在xml中选择SingleNode?,xml,vbscript,asp-classic,Xml,Vbscript,Asp Classic,发件人: xml: 猫 加图 说 哈布拉 大的 重大的 我创建了xml文件,并将其放在与经典asp文件相同的目录中: <% Set objXMLDoc = CreateObject("Microsoft.XMLDOM") objXMLDoc.async = False objXMLDoc.load("vocabulary.xml") Set Node = objXMLDoc.documentElement.selectSingleNod
猫
加图
说
哈布拉
大的
重大的
我创建了xml文件,并将其放在与经典asp文件相同的目录中:
<%
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("vocabulary.xml")
Set Node = objXMLDoc.documentElement.selectSingleNode("Word/Spanish")
document.write(Node.text)
%>
但我明白了:
Microsoft VBScript运行时错误“800a01a8”
所需对象:“objXMLDoc.documentElement”
/所以rms/reports/xmltest.asp,第7行
我做错了什么?他们得到了元素。我得到了错误。谢谢
编辑:我把这个放在:
If objXMLDoc.parseError.errorCode <> 0 Then
response.write objXMLDoc.parseError.errorCode & "ERROR CODE </br>"
response.write objXMLDoc.parseError.reason & "REASON CODE </br>"
response.write objXMLDoc.parseError.line & "LINE CODE </br>"
End If
如果objXMLDoc.parseError.errorCode为0,则
response.write objXMLDoc.parseError.errorCode&“错误代码”
response.write objXMLDoc.parseError.reason&“原因代码”
response.write objXMLDoc.parseError.line&“行代码”
如果结束
得到:
-2146697210错误代码
系统错误:-2146697210。原因码
0行代码
从下面尝试:
dim path: path = Server.MapPath("vocabulary.xml")
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(path) then
Response.Write "path '" & path & "' not found"
end if
Set objXMLDoc = CreateObject("MSXML2.DOMDocument.3.0")
objXMLDoc.async = False
if not objXMLDoc.load("vocabulary.xml") then
' report loading error
response.write "error"
end if
'objXMLDoc.load("vocabulary.xml")
If objXMLDoc.parseError.errorCode <> 0 Then
response.write objXMLDoc.parseError.errorCode & "ERROR CODE </br>"
response.write objXMLDoc.parseError.reason & "REASON CODE </br>"
response.write objXMLDoc.parseError.line & "LINE CODE </br>"
End If
Set Node = objXMLDoc.documentElement.selectSingleNode("Word/Spanish")
document.write(Node.text)
dim-path:path=Server.MapPath(“词汇表.xml”)
dim fso:set fso=CreateObject(“Scripting.FileSystemObject”)
如果不存在fso.FileExists(路径),则
响应。写入“路径”&路径&“未找到”
如果结束
设置objXMLDoc=CreateObject(“MSXML2.DOMDocument.3.0”)
objXMLDoc.async=False
如果不是objXMLDoc.load(“词汇表.xml”),那么
'报告加载错误
response.write“错误”
如果结束
'objXMLDoc.load(“词汇表.xml”)
如果objXMLDoc.parseError.errorCode为0,则
response.write objXMLDoc.parseError.errorCode&“错误代码”
response.write objXMLDoc.parseError.reason&“原因代码”
response.write objXMLDoc.parseError.line&“行代码”
如果结束
Set Node=objXMLDoc.documentElement.selectSingleNode(“Word/Spanish”)
document.write(Node.text)
编辑:
我还将xml文件更改为一个工作xml返回(bing映射)的URL,它成功了。所以我猜是文件。谢谢。我想您的xml文档没有加载。
load()
方法返回一个bool
来指示文件是否已正确加载,以便检查
if not objXMLDoc.load("vocabulary.xml") then
' report loading error
end if
parseError
属性还有一个srcText
属性,可用于确定文件中发生解析问题的位置
检查文件是否存在于正在使用的路径上也是一个好主意。使用Server.MapPath()
和Scripting.FileSystemObject
执行此操作:
dim path: path = Server.MapPath("vocabulary.xml")
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(path) then
Response.Write "path '" & path & "' not found"
end if
此外,我建议使用更高版本的XML库,
MSXML2.DomDocument
不确定。我已经尝试过:xmldoc.loadXML(“catgatospeakhablabiggrande”)
并且XML加载正确,所以XML本身是OK的。您是否尝试过objXMLDoc.load(path)
,其中path
是调用MapPath()
的结果?
dim path: path = Server.MapPath("vocabulary.xml")
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(path) then
Response.Write "path '" & path & "' not found"
end if