new
git-svn-id: svn://10.0.0.236/trunk@15311 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
35
mozilla/layout/html/tests/DumpTree.js
Normal file
35
mozilla/layout/html/tests/DumpTree.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
||||
|
||||
function traverse(node, indent)
|
||||
{
|
||||
indent += " ";
|
||||
var type = node.nodeType;
|
||||
|
||||
// if it's an element dump the tag and recurse the children
|
||||
if (type == Node.ELEMENT_NODE) {
|
||||
dump(indent + "<" + node.tagName + ">\n");
|
||||
|
||||
// go through the children
|
||||
if (node.hasChildNodes()) {
|
||||
var children = node.childNodes;
|
||||
var i, length = children.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
var child = children[i];
|
||||
traverse(child, indent);
|
||||
}
|
||||
dump(indent + "</" + node.tagName + ">\n");
|
||||
}
|
||||
}
|
||||
// it's just text, no tag, dump "Text"
|
||||
else if (type == Node.TEXT_NODE) {
|
||||
dump(indent + node.data + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
function dumpTree()
|
||||
{
|
||||
var node = document.documentElement;
|
||||
dump("Document Tree:\n");
|
||||
traverse(node, "");
|
||||
dump("\n");
|
||||
}
|
||||
Reference in New Issue
Block a user