如何在VB6中将串联字符串评估为索引XPath表达式 [英] How evaluate concatenated string as indexed XPath expression in VB6
问题描述
我通过在VB6中连接字符串来构建Xpath表达式:
I've built an Xpath expression by concatenating strings in VB6:
strXPath = "xDOC.selectNodes(" & """/GroupType1""" & ").item(" & CStr(i) & ").selectNodes(" & """/OperationStageCollection/OperationStage""" & ").length"
i是用于索引
我想评估strXPath以获得循环计数器,例如:
I want to evaluate strXPath to get a loop counter, for example:
n = CInt(strXPath)
n被声明为Integer; strXPath声明为字符串。 VB6在上面的评估表达式上引发类型不匹配错误。我肯定想念一些明显的东西。如何评估strXPath?
n is declared as Integer; strXPath is declared as string. VB6 throws a Type Mismatch error on the above evaluation expression. I must be missing something obvious. How can I evaluate strXPath?
我意识到XPath表达式本身可能存在错误,但是我想让评估工作来调试此类可能的错误。
I realize that there may be errors in the XPath expression itself, but I'd like to get the evaluation working in order to debug such possible errors.
推荐答案
尝试删除一些双引号:
iLength = xDOC.selectNodes("/GroupType1").item(i).selectNodes("/OperationStageCollection/OperationStage").length
这应该以整数形式返回您想要的 length
属性。
This should return the length
property you want, as an Integer.
然后您可以在循环中使用 iLength
。
Then you can use iLength
in your loop.
这篇关于如何在VB6中将串联字符串评估为索引XPath表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!