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&"])")
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With