Question

I have this VBA script I am writing to automate the tabling of an automation result. The example of the node I am trying to parse is as below:

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

As you can see from above, a test node can have as many results depending on the number of iterations. I used the selectNodes method to parse all the nodes in the file and this resturs the right number of elements. For each test case in the list of I return, I parse through to see how many and return in a list in a nested for each for each node. The problem is instead of returning the nested in each , the list returns all the in the text file which it is not supposed to. My code is as below.

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

Everything works but the variable testCaseResultList is supposed to return a list of contained in each node but instead it returns from ever other node. I don't know what I am doing wrong.

Was it helpful?

Solution

Try either .//result as that will return all "result" descendants of the context node (the node which testCase points to) or just result which will return all "result" children of the context node (but won't return grandchildren, great-grandchildren etc.)

Using //result returns all "result" descendants of the document root which will return every "result" node in the document

Similarly //numberOfIterations (returns all "numberOfIterations" descendants of the document root) should be replaced by either .//numberOfIterations or by just numberOfIterations

See the abbreviated syntax guide at http://www.w3.org/TR/xpath/#path-abbrev for more details

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top