我有我正在编写的这个 VBA 脚本来自动化自动化结果的表格。我试图解析的节点示例如下:
> <test id="41">
> <name>7.1.1.4_BandI_PS</name>
> <ttcnTestCaseName>7.1.1.4</ttcnTestCaseName>
> <numberOfIterations>1</numberOfIterations>
> <failureAction selected="Continue"/>
> <runMode>Normal</runMode>
> <testPicsPixitDeviation>
> <picsPixitDeviationTag>BandI</picsPixitDeviationTag>
> <picsPixitDeviationTag>PS</picsPixitDeviationTag>
> <picsPixitDeviationTag>NonCipher</picsPixitDeviationTag>
> </testPicsPixitDeviation>
> <comment/>
> <result iterationIndex="0" repeatIndex="0">
> <status>
> <status>Passed</status>
> </status>
> <resultLocation>C:\result_arch\MAC_D12wk47_v10-tc_7_1_1_4_2013-01-07_15.18.27</resultLocation>
> <startTime>2013-01-07_15.18.26</startTime>
> <executionDuration>120</executionDuration>
> <ptsIpAddress>127.0.0.1</ptsIpAddress>
> </result>
> </test>
> <test id="42">
> <name>7.1.1.8_BandI_CS</name>
> <ttcnTestCaseName>7.1.1.8</ttcnTestCaseName>
> <numberOfIterations>1</numberOfIterations>
> <failureAction selected="Continue"/>
> <runMode>Normal</runMode>
> <testPicsPixitDeviation>
> <picsPixitDeviationTag>BandI</picsPixitDeviationTag>
> <picsPixitDeviationTag>CS</picsPixitDeviationTag>
> <picsPixitDeviationTag>NonCipher</picsPixitDeviationTag>
> </testPicsPixitDeviation>
> <comment/>
> <result iterationIndex="0" repeatIndex="0">
> <status>
> <status>Passed</status>
> </status>
> <resultLocation>C:\result_arch\MAC_D12wk47_v10-tc_7_1_1_8_2013-01-07_15.20.27</resultLocation>
> <startTime>2013-01-07_15.20.27</startTime>
> <executionDuration>104</executionDuration>
> <ptsIpAddress>127.0.0.1</ptsIpAddress>
> </result>
> </test>
从上面可以看出,一个测试节点可以有尽可能多的结果,具体取决于迭代次数。我使用 selectNodes 方法来解析文件中的所有节点,这会恢复正确数量的元素。对于我返回的列表中的每个测试用例,我会解析以查看有多少,并在每个节点的嵌套列表中返回。问题不是返回嵌套在 each 中,而是返回文本文件中不应该返回的所有内容。我的代码如下。
Dim testCase As MSXML2.IXMLDOMNode
For Each testCase In testCaseNamesList
Dim passed, failed, error, totalRunTime, iterationCount As Integer
Dim passPcnt, failPcnt, errorPcnt, averageRunTime As Double
Dim testCaseName As String
Dim testCaseResultList As MSXML2.IXMLDOMNodeList
Set testCaseResultList = testCase.SelectNodes("//result")
MsgBox (testCaseResultList.Length)
testCaseName = testCase.FirstChild.Text
iterationCount = CInt(testCase.SelectSingleNode("//numberOfIterations").Text)
Dim testCaseResult As MSXML2.IXMLDOMNode
For Each testCaseResult In testCaseResultList
一切正常,但变量 testCaseResultList 应该返回包含在每个节点中的列表,而是从其他节点返回。我不知道我做错了什么。