我正在尝试使用XPath计数功能获取XML文件中特定节点的数量,但是,这总是返回错误“类型'msxml3.dll的异常:表达式未返回DOM节点”。

如何使用VBScript和MSXML DOM从XPath计数中获取返回值

Dim oXML
Dim homeId
Dim awayId
Dim homeGoals
Dim awayGoals
Set oXML = Server.CreateObject("Microsoft.XMLDOM")

oXML.async = false
oXML.SetProperty "SelectionLanguage", "XPath"
oXML.SetProperty "ServerHTTPRequest", True
oXML.validateOnParse = False
oXML.resolveExternals = False

fileName = "http://server:8090/data/results/m12345.xml")
oXML.load (fileName)

homeId = oXML.SelectSingleNode("/SoccerMatch/Team[@homeOrAway='Home']/@id").text
awayId = oXML.SelectSingleNode("/SoccerMatch/Team[@homeOrAway='Away']/@id").text
Set homeGoals = oXML.SelectSingleNode("count(/SoccerMatch/Goals/Goal[@teamId="&homeId&"])")
Set awayGoals = oXML.SelectSingleNode("count(/SoccerMatch/Goals/Goal[@teamId="&awayId&"])")

最佳答案

您只能使用返回MSXML中的Nodes的XPath,其他XPath函数只能用于最终导致选择节点的谓词中。

用:-

homeGoals = oXML.SelectNodes("/SoccerMatch/Goals/Goal[@teamId="&homeId&"]").length

关于xml - VBScript中的XPath计数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/594667/

10-09 02:05