4

次のような一連のテスト結果を含む XML ファイルを読み込んでいます。

<?xml version="1.0"?>
<testsuite>
  <build>
    <run>
      <test>
        <index>1</index>
    <id>1</id>
    <description>Description 1</description>
    <result>Pass</result>
  </test>
  <test>
    <index>2</index>
    <id>2</id>
    <description>Description 2</description>
    <result>Aborted</result>
  </test>
  <test>
    <index>3</index>
    <id>3</id>
    <description>Description 3</description>
    <result>Dependency</result>
  </test>
  <test>
    <index>4</index>
    <id>4</id>
    <description>Description 4</description>
    <result>Failed</result>
  </test>
</run>
</build>
</testsuite>

以下を使用して、リストされたノードを正常に取得できます。

 strQuery = "/testsuite/build/run/test/ (id|result)"
 Set nodeslist = xmlDoc.selectNodes(strQuery)

そして、ノード値を取得するために for each ループを使用することを知っています...

For Each objNode In nodeslist

'WHAT TO DO IN HERE...

Next

ただし、IDとそれに関連する結果を使用する必要がある時点で立ち往生しています。基本的には、この情報を取得して結果をテスト システムにアップロードしますが、現時点では、4 つの個別のテスト ノードをループして、それぞれの ID と結果を取得し、それらが相互にリンクされていることを確認する方法に行き詰まっています。つまり、それらが ID や RESULT などの変数に割り当てられる場合は、ループに戻って次のテスト ノード内の値に再割り当てする前にアップロード アクションを実行できます。

どんな助けでも大歓迎です。

4

3 に答える 3

1

のコメントからわかるように

  Dim sFSpec : sFSpec    = resolvePath( "..\data\17049535.xml" )
' Dim sXPath : sXPath    = "/testsuite/build/run/test/ (id|result)"
' msxml6.dll: NodeTest expected here. /testsuite/build/run/test/ -->(<--id|result)
  Dim sXPath : sXPath    = "/testsuite/build/run/test"
  Dim oXDoc  : Set oXDoc = CreateObject( "Msxml2.DOMDocument.6.0" )
  oXDoc.setProperty "SelectionLanguage", "XPath"
  oXDoc.async = False
  oXDoc.load sFSpec

  If 0 = oXDoc.ParseError Then
     WScript.Echo sFSpec, "looks ok"
     Dim ndlFnd : Set ndlFnd = oXDoc.selectNodes( sXPath )
     If 0 = ndlFnd.length Then
        WScript.Echo "|", sXPath, "| not found"
     Else
        WScript.Echo "found " & ndlFnd.length & " nodes."
        Dim ndTest
        For Each ndTest In ndlFnd
            WScript.Echo ndTest.childNodes(0).tagName, ndTest.childNodes(0).text
            WScript.Echo ndTest.childNodes(1).tagName, ndTest.childNodes(1).text
            WScript.Echo ndTest.selectSingleNode("description").xml
        Next
     End If

  Else
     WScript.Echo oXDoc.ParseError.Reason
  End If

XPath クエリからエラーが発生しました。出力:

E:\trials\SoTrials\answers\8194209\data\17049535.xml looks ok
found 4 nodes.
index 1
id 1
<description>Description 1</description>
index 2
id 2
<description>Description 2</description>
index 3
id 3
<description>Description 3</description>
index 4
id 4
<description>Description 4</description>

私のよりオーソドックスなXPathから、番号/位置または「サブ」XPathクエリのいずれかによって、テストノードとその子のリストを処理する方法のヒントが得られるはずです。

于 2013-06-11T17:12:52.720 に答える