This function walks a DOM tree and counts the number of nodes:
Function treeWalk(node As IXMLDOMNode, ByRef c As Integer) As Integer
Dim nodeName
Dim child As IXMLDOMNode
For Each child In node.childNodes
If child.nodeType = NODE_ELEMENT Then
c = c + 1
End If
If child.hasChildNodes Then
treeWalk child, c
End If
Next
treeWalk = c
End Function