gecko-dev/dom/tests/js/DumpHTML.js
1998-04-13 20:24:54 +00:00

58 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Dump the html content in html format
//
function html(node, indent)
{
Dump("\n")
//indent += " "
var type = node.GetNodeType()
if (type == 2) {
// open tag
//Dump("\ndump tag\n")
Dump("<" + node.GetTagName())
// dump the attributes if any
attributes = node.GetAttributes()
if (null != attributes) {
var countAttrs = attributes.GetLength()
var index = 0
while(index < countAttrs) {
att = attributes.Item(index)
if (null != att) {
//Dump("\ndump attribute\n")
Dump(" " + att.ToString())
}
index++
}
}
// close tag
Dump(">")
// recursively dump the children
if (node.HasChildNodes()) {
// get the children
var children = node.GetChildNodes()
var length = children.GetLength()
var child = children.GetNextNode()
var count = 0;
while(count < length) {
html(child, indent)
child = children.GetNextNode()
count++
}
}
}
// if it's a piece of text just dump the text
else if (type == 6) {
//Dump("\ndump text\n")
Dump(node.data)
}
}
html(document.documentElement, "")
Dump("\n")