Option
Explicit
Sub
Test01()
Dim
xmlDoc
As
Object
Dim
xmlNode
As
Object
Dim
wksOutput
As
Excel.Worksheet
Dim
strValue
As
String
Dim
avnt
As
Variant
Set
wksOutput = Worksheets(
"Sheet1"
)
Set
xmlDoc = CreateObject(
"MSXML2.DOMDocument"
)
xmlDoc.async =
False
If
Not
xmlDoc.Load(
"D:\95810.txt"
)
Then
MsgBox xmlDoc.parseError.reason
End
If
Set
xmlNode = xmlDoc.SelectSingleNode(
"./Scope/Settings"
)
avnt = Split(xmlNode.FirstChild.NodeValue, vbLf)
wksOutput.Range(
"A1"
).Value =
"SampleRate:"
If
GetKeyValue(avnt,
"Timebase Data"
,
"SampleRate"
, strValue)
Then
wksOutput.Range(
"B1"
).Value = strValue
Else
wksOutput.Range(
"B1"
).Value =
""
End
If
Set
xmlNode = xmlDoc.SelectSingleNode(
"./Scope/TraceData"
)
Dim
vntXY()
As
Variant
Dim
j
As
Long
Dim
i
As
Long
For
i = 0
To
xmlNode.ChildNodes.Length - 1
With
xmlNode.ChildNodes(i)
ReDim
vntXY(0
To
Val(.Attributes.getNamedItem(
"NumElements"
).NodeValue) - 1, 0
To
1)
For
j = LBound(vntXY)
To
UBound(vntXY)
With
.ChildNodes(j).Attributes
vntXY(j, 0) = Val(.getNamedItem(
"X"
).NodeValue)
vntXY(j, 1) = Val(.getNamedItem(
"Y"
).NodeValue)
End
With
Next
wksOutput.Range(
"A3:B3"
).Offset(, i * 2).Font.Bold =
True
wksOutput.Range(
"A3:B3"
).Offset(, i * 2).Value = Array(.nodeName &
" X"
, .nodeName &
" Y"
)
wksOutput.Range(
"A4"
).Offset(, i * 2).Resize(1 + UBound(vntXY), 2).Value = vntXY
End
With
DoEvents
Next
End
Sub
Private
Function
GetKeyValue(List
As
Variant
, Section
As
String
, Key
As
String
,
ByRef
KeyValue
As
String
)
As
Boolean
Dim
blnSection
As
Boolean
Dim
vntElement
As
Variant
For
Each
vntElement
In
List
If
Left$(vntElement, 1) =
"["
And
Right$(vntElement, 1) =
"]"
Then
If
0 = StrComp(
"["
& Section &
"]"
, vntElement, vbTextCompare)
Then
blnSection =
True
Else
blnSection =
False
End
If
Else
If
blnSection
Then
If
0 = StrComp(Key, Trim$(Left$(vntElement, InStr(1, vntElement,
"="
) - 1)), vbTextCompare)
Then
KeyValue = Trim$(Right$(vntElement, Len(vntElement) - InStr(1, vntElement,
"="
)))
GetKeyValue =
True
Exit
Function
End
If
End
If
End
If
Next
End
Function