VBScript 中的 XPath 计数 [英] XPath count in VBScript

查看:26
本文介绍了VBScript 中的 XPath 计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 XPath 计数函数获取 XML 文件中特定节点的数量,但是,这一直返回错误'msxml3.dll 类型的异常:表达式不返回 DOM 节点."

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."

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

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&"])")

推荐答案

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

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.

使用:-

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

这篇关于VBScript 中的 XPath 计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆