Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath count in VBScript

I am trying to get the number of specific nodes in an XML file using the XPath count function, however, this keeps returning an error "An exception of type 'msxml3.dll: Expression does not return a DOM node."

How do I get the return value from an XPath count using VBScript and MSXML DOM

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&"])")
like image 350
Xetius Avatar asked Feb 27 '09 13:02

Xetius


1 Answers

You can only use XPaths that return Nodes in MSXML, other XPath functions can only be used in predicates that ultimately result in a selection of nodes.

Use:-

homeGoals = oXML.SelectNodes("/SoccerMatch/Goals/Goal[@teamId="&homeId&"]").length
like image 162
AnthonyWJones Avatar answered Oct 21 '22 12:10

AnthonyWJones