给定以下 XML
<Tests>
<AutomatedTests>
<TestName>Test1</TestName>
<FunctionalLibraries>
<FunctionalLibrary>CommonLib</FunctionalLibrary>
<FunctionalLibrary>AppTestLib</FunctionalLibrary>
<FunctionalLibrary>Test1Lib</FunctionalLibrary>
</FunctionalLibraries>
</AutomatedTests>
<AutomatedTests>
<TestName>Test2</TestName>
<FunctionalLibraries>
<FunctionalLibrary>CommonLib</FunctionalLibrary>
<FunctionalLibrary>AppTestLib</FunctionalLibrary>
<FunctionalLibrary>Test2Lib</FunctionalLibrary>
</FunctionalLibraries>
</AutomatedTests>
<AutomatedTests>
<TestName>Test3</TestName>
<FunctionalLibraries>
<FunctionalLibrary>CommonLib</FunctionalLibrary>
<FunctionalLibrary>Test3Lib</FunctionalLibrary>
</FunctionalLibraries>
</AutomatedTests>
</Tests>
使用 VBScript,我如何找到所有 /Tests/AutomatedTests 节点共有的所有 /Tests/AutomatedTests/FunctionalLibraries 节点。
根据上面的xml,结果应该是...
<CommonTestLibraries>
<FunctionalLibrary>CommonLib</FunctionalLibrary>
</CommonTestLibraries>
谢谢
这就是我所拥有的,我希望有一种更简单的方法,因为我必须在同一个文件上多次执行此操作。
set tempDict = CreateObject("Scripting.Dictionary")
set commonDict = CreateObject("Scripting.Dictionary")
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Load(fileName)
set testNodes = xmlDoc.SelectNodes("/Tests/AutomatedTests")
isFirst = true
for each testNode in testNodes
set functionalLibraryNodes = testNode.SelectNodes("FunctionLibraries/FunctionLibrary")
For Each functionalLibraryNode in functionalLibraryNodes
If not tempDict.Exists(functionalLibraryNode.Text) Then
tempDict.Add functionalLibraryNode.Text, functionalLibraryNode.Text
End If
Next
If NOT isFirst Then
for each item in commonDict
if tempDict.Exists(item) = false Then
commonDict.Remove item
End If
Next
Else
Set commonDict = tempDict
isFirst = false
End If
Set tempDict = nothing
Set tempDict = CreateObject("Scripting.Dictionary")
Next