AW: xml: alle child nodes eines parent nodes auslesen
19.07.2018 15:21:09
PeterK
Hallo
Könnte in etwa so ausschauen
Option Explicit
Dim xDoc As MSXML2.DOMDocument60
Public Sub LoadDocument()
Set xDoc = New MSXML2.DOMDocument60
xDoc.validateOnParse = True
If xDoc.Load("C:\Users\ich\Downloads\child_nodes_of_parent_node.xml") Then
' The document loaded successfully.
Else
' The document failed to load.
End If
End Sub
Sub GetKD_ID(myCustomer As String)
Dim oSeqNodes As IXMLDOMNodeList
Dim oSeqNode As IXMLDOMNode
Dim oSeqChild As IXMLDOMNode
Set oSeqNodes = xDoc.SelectNodes("//BrandData/" & myCustomer)
If oSeqNodes.Length = 0 Then
'show some message
Else
For Each oSeqNode In oSeqNodes
For Each oSeqChild In oSeqNode.ChildNodes
Debug.Print oSeqChild.nodeName
Next
Next
End If
End Sub
Sub GetKD_ID_Info(myCustomer As String, myK_ID As String)
Dim oSeqNodes As IXMLDOMNodeList
Dim oSeqNode As IXMLDOMNode
Dim oSeqChild As IXMLDOMNode
Set oSeqNodes = xDoc.SelectNodes("//BrandData/" & myCustomer & "/" & myK_ID)
If oSeqNodes.Length = 0 Then
'show some message
Else
For Each oSeqNode In oSeqNodes
For Each oSeqChild In oSeqNode.ChildNodes
Debug.Print oSeqChild.nodeName, ":", oSeqChild.Text
Next
Next
End If
End Sub
Sub Finish()
Set xDoc = Nothing
End Sub
Sub RunXml()
LoadDocument
GetKD_ID "Customer_Deutschland"
GetKD_ID_Info "Customer_Deutschland", "Kd_ID_Test8"
Finish
End Sub