XML is structured data, so use a structured method (XPath) to work with it. Repeated/Nested getElementsByTagName()
loose the hierarchical relations. In Code:
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
Dim sFSpec : sFSpec = goFS.GetAbsolutePathName("..\testdata\xml\so23686152.xml")
Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument")
objMSXML.setProperty "SelectionLanguage", "XPath"
objMSXML.async = False
objMSXML.load sFSpec
If 0 = objMSXML.parseError Then
Dim ndlReg : Set ndlReg = objMSXML.selectNodes("/root/registration")
Dim ndReg
For Each ndReg In ndlReg
WScript.Echo ndReg.selectSingleNode("serialnumber").text
Dim ndMod
For Each ndMod In ndReg.selectNodes("modules/module")
WScript.Echo " " _
, ndMod.firstChild.text _
, ndMod.selectSingleNode("id").text _
, ndMod.childNodes(2).text
Next
Next
Else
WScript.Echo objMSXML.parseError.reason
End If
output:
1234567890
SERVER : A 15 1
SERVER : B 40 1
0987654321
SERVER : 1 15 1
SERVER : 2 40 1
SERVER : 3 15 1
SERVER : 4 40 1