I am using VBA to get All the attributes and values from the XML parent node.
Here is the XML:
<Elements>
<Details>
<Name>ABC</Name>
<Address>123ABC</Address>
</Details>
<Dept>
<Deptname>IT</Deptname>
<ID>A123</ID>
</Dept>
</Elements>
This is the code I am using in VBA
sub test()
Dim XMLFile As Object
Dim XMLFileName As String
Set XMLFile = CreateObject("Microsoft.XMLDOM")
XMLFileName = "C:\Users\Input.xml"
XMLFile.async = False
XMLFile.Load (XMLFileName)
XMLFile.validateOnParse = False
Dim mainnode As Object
Dim node As Object
Set mainnode = XMLFile.SelectNodes("//Elements")
For Each node In mainnode
Dim child As Variant
For Each child In node.ChildNodes
Debug.Print child.Name
Next child
Next node
End sub
This is the output I am expecting.
Details
Name
Address
Dept
deptname
ID
I am getting errors executing the above code. Could someone help me in getting this resolved. Thanks!