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: // return a string representing the html content in html format michael@0: // michael@0: function htmlString(node, indent) michael@0: { michael@0: var html = "" michael@0: indent += " " michael@0: michael@0: var type = node.nodeType michael@0: if (type == Node.ELEMENT) { michael@0: michael@0: // open tag michael@0: html += "\n" + indent + "<" + 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: html += " " michael@0: html += att.name + "=" + att.value; michael@0: } michael@0: index++ michael@0: } michael@0: } michael@0: michael@0: // end tag michael@0: html += ">" 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 += htmlString(child, indent) michael@0: count++ michael@0: } michael@0: } michael@0: michael@0: // close tag michael@0: html += "\n" + indent + "" michael@0: } michael@0: // if it's a piece of text just dump the text michael@0: else if (type == Node.TEXT) { michael@0: html += node.data michael@0: } michael@0: michael@0: return html; michael@0: } michael@0: michael@0: htmlString(document.documentElement, "") michael@0: michael@0: michael@0: