// start writing about this element
document.write(depth + "/" + count + ": Element is type = " +
node.nodeType + ", name = " + node.nodeName + ", ");
// if it's tag show tagname else show value
if (node.nodeType == 1) {
document.write(" tag = <");
document.write(node.tagName);
document.write(">");
}
else {
document.write("value = '" + node.nodeValue + "'");
}
// if there are any children
if (node.hasChildNodes) {
// get the children
var cn = node.childNodes;
// tell us how many
document.write(". The element has " + cn.length + " child")
if (cn.length > 1) document.write("ren");
document.write(".<br />");
// process the children
depth++;
for (var c = 0; c < cn.length; c++) {
family(cn[c],c);
}
depth--;
}
else {
document.write(".<br />");
}
}
--------------------------