michael@0: /* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: // michael@0: // travers the html tree and dump out the type of element michael@0: // michael@0: function traverse(node, indent) michael@0: { michael@0: dump("\n") michael@0: indent += " " michael@0: var type = node.nodeType; michael@0: michael@0: // if it's an element dump the tag and recurse the children michael@0: if (type == Node.ELEMENT_NODE) { michael@0: michael@0: dump(indent + node.tagName) michael@0: michael@0: // go through the children michael@0: if (node.hasChildNodes()) { michael@0: var children = node.childNodes; michael@0: var length = children.length; michael@0: var count = 0; michael@0: while(count < length) { michael@0: child = children[count] michael@0: traverse(child, indent) michael@0: count++ michael@0: } michael@0: } michael@0: } michael@0: // it's just text, no tag, dump "Text" michael@0: else if (type == Node.TEXT_NODE) { michael@0: dump(indent + "Text") michael@0: } michael@0: } michael@0: michael@0: var node = document.documentElement michael@0: michael@0: traverse(node, "") michael@0: dump("\n") michael@0: michael@0: