probier mal:
Option Explicit
Sub Test01()
Dim xmlDoc As Object 'MSXML2.DOMDocument
Dim xmlNode As Object 'MSXML2.IXMLDOMNode
Dim wksOutput As Excel.Worksheet
Dim strValue As String
Dim avnt As Variant
Set wksOutput = Worksheets("Sheet1")
'>> loading xml >>
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
If Not xmlDoc.Load("D:\95810.txt") Then
MsgBox xmlDoc.parseError.reason
End If
'<< loading xml <<
'>> SampleRate >>
Set xmlNode = xmlDoc.SelectSingleNode("./Scope/Settings")
avnt = Split(xmlNode.FirstChild.NodeValue, vbLf)
'# output
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
'<< SampleRate <<
'>> Channels X/Y-Data >>
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
'# output
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
'<< Channels X/Y-Data <<
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
|