为下面的xml做SelectSingleNode的正确方法是什么,我想要p50,p90,p95和p99的百分位值。我也有很多,所以我循环它们但我只得到第一个
<Measure>
<Class>Timer</Class>
<Name>EMF-01-Launch</Name>
<Type>Response time[s]</Type>
<Unit>Seconds</Unit>
<Timebound1>0.000000000</Timebound1>
<Timebound2>0.000000000</Timebound2>
<IDMeasureType>3</IDMeasureType>
<IDMeasureClass>2</IDMeasureClass>
<TypeDisplayStr>Response time[s]</TypeDisplayStr>
<SumCount1>34778.000000000</SumCount1>
<SumCount2>20619.000000000</SumCount2>
<SumSum>2885.826000000</SumSum>
<SumSqSum>1084.245452000</SumSqSum>
<MinMin>0.031000000</MinMin>
<MaxMax>5.866000000</MaxMax>
<Avg>0.139959552</Avg>
<Stdd>0.181648280</Stdd>
<SumTimeboundCount1>
<Percent>0.000000000</Percent>
0
</SumTimeboundCount1>
<SumTimeboundCount2>
<Percent>0.000000000</Percent>
0
</SumTimeboundCount2>
<SortNo>0</SortNo>
<Percentiles>
<ID>0</ID>
<Values>
<Value>
<Percent>50</Percent>
<Value>0.109000000</Value>
</Value>
<Value>
<Percent>90</Percent>
<Value>0.235000000</Value>
</Value>
<Value>
<Percent>95</Percent>
<Value>0.314000000</Value>
</Value>
<Value>
<Percent>99</Percent>
<Value>0.784000000</Value>
</Value>
</Values>
</Percentiles>
For Each SNode in scriptNodes
scriptName = SNode.SelectSingleNode("Name").text
'For each measure of type Timer
Set timerNodes = SNode.selectNodes("Measures/Measure")
'msgbox (timerNodes.length)
For Each TNode in timerNodes
If TNode.SelectSingleNode("Class").text = "Timer" then
' Extract the timer data
timerName = TNode.SelectSingleNode("Name").text
min = TNode.SelectSingleNode("MinMin").text
avg = TNode.SelectSingleNode("Avg").text
max = TNode.SelectSingleNode("MaxMax").text
stDev = TNode.SelectSingleNode("Stdd").text
count = TNode.SelectSingleNode("SumCount2").text
p50 = TNode.SelectSingleNode("Percentiles/Values/Value[1]/Value").text
msgbox (p50)
p90 = TNode.SelectSingleNode("//Percentiles/Values/Value[2]/Value").text
p95 = TNode.SelectSingleNode("//Percentiles/Values/Value[3]/Value").text
p99 = TNode.SelectSingleNode("//Percentiles/Values/Value[4]/Value").text
'Write to File
fileHandle.WriteLine(scriptName+","+timerName+","+min+","+avg+","+max+","+stDev+","+count+","+p50+","+p90+","+p95+","+p99)
end if
Next 'TNode in timerNodes
Next 'SNode in scriptNodes
fileHandle.Close
答案 0 :(得分:0)
您需要系统地进行“向下钻取”,找出代码中您可以/必须收集信息的位置,并且不要忘记selectNodes()
。演示代码以帮助您进行实验:
Dim sFSpec : sFSpec = goFS.GetAbsolutePathName("..\testdata\xml\22955875.xml")
Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument.6.0")
objMSXML.setProperty "SelectionLanguage", "XPath"
objMSXML.async = False
objMSXML.load sFSpec
If 0 = objMSXML.parseError Then
WScript.Echo "ok"
Dim dicData : Set dicData = CreateObject("Scripting.Dictionary")
dicData("MinMin") = ""
dicData("MaxMax") = ""
Dim TNode : Set TNode = objMSXML.SelectSingleNode("/Measure") ' fake for fragment
If TNode Is Nothing Then
WScript.Echo "no TNode"
Else
Dim sKey, ndFnd, ndlFnd, aPX, i
For Each sKey In dicData.Keys
Set ndFnd = TNode.selectSingleNode(sKey)
If ndFnd Is Nothing Then
WScript.Echo sKey, "not found"
Else
dicData(sKey) = ndFnd.text
End If
Next
Set ndlFnd = TNode.selectNodes("Percentiles/Values/Value")
If 0 = ndlFnd.length Then
WScript.Echo "no values"
Else
ReDim aPX(ndlFnd.length - 1)
For i = 0 To UBound(aPX)
aPX(i) = "??"
Set ndFnd = ndlFnd(i).selectSingleNode("Value")
If ndFnd Is Nothing Then
WScript.Echo "no value"
Else
aPX(i) = ndFnd.text
End If
Next
dicData("px") = "[" & Join(aPX, ",") & "]"
End If
For Each sKey In dicData.Keys()
WScript.Echo sKey, "=>", dicData(sKey)
Next
WScript.Echo Join(dicData.Items(), ",")
End If
Else
WScript.Echo objMSXML.parseError.reason
End If
outut:
ok
MinMin => 0.031000000
MaxMax => 5.866000000
px => [0.109000000,0.235000000,0.314000000,0.784000000]
0.031000000,5.866000000,[0.109000000,0.235000000,0.314000000,0.784000000]