dom/tests/js/DumpHTML.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:21ff46774270
1 /* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
7 //
8 // Dump the html content in html format
9 //
10 function html(node)
11 {
12 var type = node.nodeType;
13 if (type == Node.ELEMENT_NODE) {
14
15 // open tag
16 dump("<" + node.tagName)
17
18 // dump the attributes if any
19 attributes = node.attributes;
20 if (null != attributes) {
21 var countAttrs = attributes.length;
22 var index = 0
23 while(index < countAttrs) {
24 att = attributes[index];
25 if (null != att) {
26 dump(" " + att.value)
27 }
28 index++
29 }
30 }
31
32 // close tag
33 dump(">")
34
35 // recursively dump the children
36 if (node.hasChildNodes()) {
37 // get the children
38 var children = node.childNodes;
39 var length = children.length;
40 var count = 0;
41 while(count < length) {
42 child = children[count]
43 html(child)
44 count++
45 }
46 dump("</" + node.tagName + ">");
47 }
48
49
50 }
51 // if it's a piece of text just dump the text
52 else if (type == Node.TEXT_NODE) {
53 dump(node.data)
54 }
55 }
56
57 html(document.documentElement)
58 dump("\n")

mercurial