|
1 // ---------------------- |
|
2 // DumpDOM(node) |
|
3 // |
|
4 // Call this function to dump the contents of the DOM starting at the specified node. |
|
5 // Use node = document.documentElement to dump every element of the current document. |
|
6 // Use node = top.window.document.documentElement to dump every element. |
|
7 // |
|
8 // 8-13-99 Updated to dump almost all attributes of every node. There are still some attributes |
|
9 // that are purposely skipped to make it more readable. |
|
10 // ---------------------- |
|
11 function DumpDOM(node) |
|
12 { |
|
13 dump("--------------------- DumpDOM ---------------------\n"); |
|
14 |
|
15 DumpNodeAndChildren(node, ""); |
|
16 |
|
17 dump("------------------- End DumpDOM -------------------\n"); |
|
18 } |
|
19 |
|
20 |
|
21 // This function does the work of DumpDOM by recursively calling itself to explore the tree |
|
22 function DumpNodeAndChildren(node, prefix) |
|
23 { |
|
24 dump(prefix + "<" + node.nodeName); |
|
25 |
|
26 var attributes = node.attributes; |
|
27 |
|
28 if ( attributes && attributes.length ) |
|
29 { |
|
30 var item, name, value; |
|
31 |
|
32 for ( var index = 0; index < attributes.length; index++ ) |
|
33 { |
|
34 item = attributes.item(index); |
|
35 name = item.nodeName; |
|
36 value = item.nodeValue; |
|
37 |
|
38 if ( (name == 'lazycontent' && value == 'true') || |
|
39 (name == 'xulcontentsgenerated' && value == 'true') || |
|
40 (name == 'id') || |
|
41 (name == 'instanceOf') ) |
|
42 { |
|
43 // ignore these |
|
44 } |
|
45 else |
|
46 { |
|
47 dump(" " + name + "=\"" + value + "\""); |
|
48 } |
|
49 } |
|
50 } |
|
51 |
|
52 if ( node.nodeType == 1 ) |
|
53 { |
|
54 // id |
|
55 var text = node.getAttribute('id'); |
|
56 if ( text && text[0] != '$' ) |
|
57 dump(" id=\"" + text + "\""); |
|
58 } |
|
59 |
|
60 if ( node.nodeType == Node.TEXT_NODE ) |
|
61 dump(" = \"" + node.data + "\""); |
|
62 |
|
63 dump(">\n"); |
|
64 |
|
65 // dump IFRAME && FRAME DOM |
|
66 if ( node.nodeName == "IFRAME" || node.nodeName == "FRAME" ) |
|
67 { |
|
68 if ( node.name ) |
|
69 { |
|
70 var wind = top.frames[node.name]; |
|
71 if ( wind && wind.document && wind.document.documentElement ) |
|
72 { |
|
73 dump(prefix + "----------- " + node.nodeName + " -----------\n"); |
|
74 DumpNodeAndChildren(wind.document.documentElement, prefix + " "); |
|
75 dump(prefix + "--------- End " + node.nodeName + " ---------\n"); |
|
76 } |
|
77 } |
|
78 } |
|
79 // children of nodes (other than frames) |
|
80 else if ( node.childNodes ) |
|
81 { |
|
82 for ( var child = 0; child < node.childNodes.length; child++ ) |
|
83 DumpNodeAndChildren(node.childNodes[child], prefix + " "); |
|
84 } |
|
85 } |