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: // Dump the html content in html format michael@0: // michael@0: function html(node) michael@0: { michael@0: var type = node.nodeType; michael@0: if (type == Node.ELEMENT_NODE) { michael@0: michael@0: // open tag michael@0: dump("<" + node.tagName) michael@0: michael@0: // dump the attributes if any michael@0: attributes = node.attributes; michael@0: if (null != attributes) { michael@0: var countAttrs = attributes.length; michael@0: var index = 0 michael@0: while(index < countAttrs) { michael@0: att = attributes[index]; michael@0: if (null != att) { michael@0: dump(" " + att.value) michael@0: } michael@0: index++ michael@0: } michael@0: } michael@0: michael@0: // close tag michael@0: dump(">") michael@0: michael@0: // recursively dump the children michael@0: if (node.hasChildNodes()) { michael@0: // get the children 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: html(child) michael@0: count++ michael@0: } michael@0: dump(""); michael@0: } michael@0: michael@0: michael@0: } michael@0: // if it's a piece of text just dump the text michael@0: else if (type == Node.TEXT_NODE) { michael@0: dump(node.data) michael@0: } michael@0: } michael@0: michael@0: html(document.documentElement) michael@0: dump("\n")