Skip to content

Commit 2c9d080

Browse files
committed
add simple recursive printNode from examples to main module
1 parent 699cc93 commit 2c9d080

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/PrintDomTree.bas

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Attribute VB_Name = "PrintDomTree"
2+
Option Explicit
3+
4+
Public Sub PrintNode(ByVal node As cdpDOMNode, Optional ByVal pad As String = "")
5+
Debug.Print pad & "<" & node.nodeName & "(" & node.nodeType & ") " & "name='" & node.localName & "' attributes:" & Concat(node.attributes) & IIf(node.childNodeCount > 0, "", " />")
6+
If node.childNodeCount > 0 Then
7+
Dim v As Variant
8+
For Each v In node.children
9+
PrintNode v, pad & " "
10+
Next v
11+
Debug.Print pad & "/>"
12+
End If
13+
End Sub
14+
15+
Private Function Concat(ByVal attrib As Collection)
16+
Dim v As Variant
17+
Dim key As String, Value As String
18+
Dim counter As Integer
19+
If attrib.count = 0 Then Concat = "''"
20+
For Each v In attrib
21+
If (counter Mod 2) = 0 Then
22+
key = CStr(v)
23+
Else
24+
Value = "'" & CStr(v) & "'"
25+
If counter > 1 Then Concat = Concat & ","
26+
Concat = Concat & key & "=" & Value
27+
End If
28+
counter = counter + 1
29+
Next v
30+
End Function
31+
32+

0 commit comments

Comments
 (0)