Option Explicit
Public Sub ParseXml()
Dim xml As Object 'MSXML2.DOMDocument60
Set xml = CreateObject("MSXML2.DOMDocument")
Call xml.SetProperty("SelectionLanguage", "XPath")
xml.validateOnParse = True
xml.async = False
' XML aus Datei laden
If Not xml.Load("C:\Test\Beispiel.xml") Then
Call MsgBox( _
Buttons:=vbCritical, _
Prompt:=xml.ParseError.Reason, _
Title:="Fehler in Zeile " & xml.ParseError.Line & ", Spalte " & xml.ParseError.LinePos)
Exit Sub
End If
'VARIANTE 1:
Dim xmlAttr As Object 'MSXML2.IXMLDOMAttribute
Set xmlAttr = xml.SelectSingleNode("//renderedResult/@concentration")
Call MsgBox("'" & xmlAttr.Name & "' = " & xmlAttr.NodeValue, vbInformation)
' 'VARIANTE 2:
' Dim xmlElem As Object 'MSXML2.IXMLDOMElement
' Dim xmlAttr As Object 'MSXML2.IXMLDOMAttribute
'
' Set xmlElem = xml.SelectSingleNode("//renderedResult[@concentration]")
' Set xmlAttr = xmlElem.GetAttributeNode("concentration")
'
' Call MsgBox("'" & xmlAttr.Name & "' = " & xmlAttr.NodeValue, vbInformation)
End Sub
Grüße
|