为什么我能够从一个 XML 节点获取文本,但不能从其同级节点获取文本?我现在肯定做错了什么,实际上我曾经一度让它工作过,但当时我选择了错误的 sibling 。下面的代码返回并将 strRespone 写入我的源代码。但我在下一个时收到错误“”。
错误: Microsoft VBScript 运行时错误“800a01a8”
需要对象
/preview.asp,第 905 行(行:strAuthCode = strBMLAuthCode.text)
代码:
Dim NodeList, Node, SubNode
Set NodeList = xmlDom.documentElement.selectNodes("onlineresponse/authorizationresponse")
Set strBMLResponse = xmlDom.SelectSingleNode("//response")
strResponse = strBMLResponse.text
Response.Write "<!--strResponse: " & strResponse & "-->"
If strResponse = "000" Then '//SUCCESS!!
Set strBMLAuthCode = xmlDom.SelectSingleNode("//id")
strAuthCode = strBMLAuthCode.text
Response.Write "strAuthCode: " & strAuthCode & "<br>"
Set strBMLAcctNum = xmlDom.SelectSingleNode("//number")
strAcctNum = strBMLAcctNum.text
Response.Write "strAcctNum: " & strAcctNum & "<br>"
strCCNum = strAcctNum
Else ' if strResponse <> '000'...
没有 XML: 我想通了..将 xml 删除作为我们安全的预防措施。
谢谢!
编辑: 我会尽快发布答案。
最佳答案
你的匈牙利表示法太糟糕了。您可以对既是字符串又不是字符串的事物使用“str”前缀,即 strBMLResponse 不是字符串!考虑按如下方式重命名您的值:
Dim xmlResponse
Set xmlResponse = xmlDom.SelectSingleNode("//response")
Dim strResponse
strResponse = xmlResponse.text
其次,您没有错误检查,即您的代码始终假设 Set 始终分配有效的对象。但是,在实践中可能存在什么也没有返回
的情况,即
If strResponse = "000" Then
Dim xmlAuthCode
Set xmlAuthCode = xmlDom.SelectSingleNode("//litletxnid")
If Not (xmlAuthCode is Nothing) Then
Dim strAuthCode
strAuthCode = xmlAuthCode.text
Rem ...
End If
End If
我对您提供的 XML 和代码进行了一些检查,并且该错误不可重现,因此,我假设信息不足。即我猜测 xmlDom 的内容实际上并不包含“litletxnid”节点。您需要进行一些额外的检查来确认或否认这种情况。
编辑:
感谢您提供的额外信息。正如前面提到的,我在使用所提供的信息重现问题时遇到了麻烦。这意味着需要更多的故障排除,特别是在 litletxnid
节点上进行深入分析。您还有其他方法可以获取它,例如:
Dim xmlAuthCode
Set xmlAuthCode = xmlDom.documentElement.firstChild.firstChild
Rem You can add debugging here like view xmlAuthCode.xml
关于xml - 为什么我能够从一个 XML 节点获取文本,但不能从其同级节点获取文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12264203/