Mozilla/mozilla/dom/tests/js/HTMLString.js
dario 85b6df8b9b another js example
git-svn-id: svn://10.0.0.236/trunk@241 18797224-902f-48f8-a5cc-f745e15eee43
1998-04-14 18:14:55 +00:00

62 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.

//
// return a string representing the html content in html format
//
function htmlString(node, indent)
{
var html = ""
indent += " "
var type = node.GetNodeType()
if (type == Node.ELEMENT) {
// open tag
html += indent + "<" + node.GetTagName()
// dump the attributes if any
attributes = node.GetAttributes()
if (null != attributes) {
html += " "
var countAttrs = attributes.GetLength()
var index = 0
while(index < countAttrs) {
att = attributes.Item(index)
if (null != att) {
html += att.ToString()
}
index++
}
}
// end tag
html += ">"
// 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 += htmlString(child, indent)
child = children.GetNextNode()
count++
}
}
// close tag
html += "</" + node.GetTagName() + ">"
}
// if it's a piece of text just dump the text
else if (type == Node.TEXT) {
html += node.data
}
return html;
}
htmlString(document.documentElement, "")