Private Sub Command1_Click()
Dim xmlDocA As New MSXML2.DOMDocument
Dim xmlDocB As New MSXML2.DOMDocument
Dim ndsA As IXMLDOMNodeList
Dim ndsB As IXMLDOMNodeList
Dim ndA As IXMLDOMNode
Dim ndB As IXMLDOMNode
Dim cnt As Long
Dim sGauge As String
Dim sMouse As String
Dim sSource() As String
xmlDocA.loadXML Replace(Form1.RichTextBox1.Text, vbCrLf, vbLf)
xmlDocB.loadXML Replace(Form2.RichTextBox1.Text, vbCrLf, vbLf)
If Len(xmlDocA.xml) = 0 Or Len(xmlDocB.xml) = 0 Then Exit Sub
Set ndsA = xmlDocA.getElementsByTagName("Gauge")
Set ndsB = xmlDocB.getElementsByTagName("Gauge")
If (ndsA Is Nothing) Or ndsB Is Nothing Then Exit Sub
ReDim sSource(ndsA.length - 1)
Do
Set ndA = ndsA(cnt).selectSingleNode("Mouse")
Set ndB = ndsB(cnt).selectSingleNode("Mouse")
If Not (ndA Is Nothing) And Not (ndB Is Nothing) Then
'combine two <Gauge> nodes, excluding <Mouse> nodes
sGauge = Replace(Replace(ndsA(cnt).xml, vbTab, ""), Replace(ndA.xml, vbTab, ""), "")
sGauge = sGauge & Replace(Replace(ndsB(cnt).xml, vbTab, ""), Replace(ndB.xml, vbTab, ""), "")
sGauge = Replace(sGauge, "</Gauge><Gauge>", "")
'combine two <Mouse> nodes
sMouse = Replace(ndA.xml, vbTab, "") & Replace(ndB.xml, vbTab, "")
sMouse = Replace(sMouse, "</Mouse><Mouse>", "")
'append <Mouse> node by updating </Gauge>
sGauge = Replace(sGauge, "</Gauge>", sMouse & vbCrLf & "</Gauge>")
'clean up
Do While InStr(1, sGauge, vbCrLf & vbCrLf) > 0
sGauge = Replace(sGauge, vbCrLf & vbCrLf, vbCrLf)
Loop
Do While InStr(1, sGauge, vbLf & vbLf) > 0
sGauge = Replace(sGauge, vbLf & vbLf, vbLf)
Loop
sSource(cnt) = sGauge
End If
cnt = cnt + 1
Loop While cnt < ndsA.length And cnt < ndsB.length
Form1.RichTextBox1.Text = Join(sSource, vbCrLf)
End Sub