// ---------------------- // DumpDOM(node) // // Call this function to dump the contents of the DOM starting at the specified node. // Use node = document.documentElement to dump every element of the current document. // Use node = top.window.document.documentElement to dump every element. // // DumpXDOM(node) // // Call this function to dump the contents of the XML DOM starting at the specified node. // Use node = document to dump every element of the current composite xml structure. // ... This wishy-washy wording was brought to you by chrome, xul and rdf. // Use silent to cause DumpHTML to return a string instead of dumping to the console. // // DumpHTML(node,silent) // // Call this function to dump the contents of an HTML DOM starting at the specified document. // Use node = window._content.document to dump every element of the current document. // Use silent to cause DumpHTML to return a string instead of dumping to the console. // // // 8-13-99 Updated to dump almost all attributes of every node. There are still some attributes // that are purposely skipped to make it more readable. // 10-26-00 Some of those things are very important for view-source. // These changes should allow serialization of live pages // Uses include: view-source, save as, print, edit, save as charset, print preview // ---------------------- function DumpDOM(node) { dump("--------------------- DumpDOM ---------------------\n"); dump(DumpNodeAndChildren(node, "",0)); dump("------------------- End DumpDOM -------------------\n"); } // warning, html is slightly hacked it wants a #document // if you want to pass an internal portion of a document please use // DumpNodeAndChildren(node,"",1) function DumpHTML(node,silent) { var code=""; if ( node.childNodes ){ for ( var child = 0; child < node.childNodes.length; child++ ) code+=DumpNodeAndChildren(node.childNodes[child], "", 1); } if (silent) return code; dump(code); } function DumpXDOM(node,silent) { var code=DumpNodeAndChildren(node, "",2); if (silent) return code; dump("--------------------- DumpXDOM ---------------------\n"); dump(code); dump("------------------- End DumpXDOM -------------------\n"); } // This function does the work of DumpDOM by recursively calling itself to explore the tree // Quirks: // top. is not set correctly when Dump???? is called from chrome // if you want to dump all frames as a group you will need to clobber top // to the correct window. function DumpNodeAndChildren(node, prefix, xml) { if ( xml && node.nodeName == "#text" ) return node.data+"\n"; if ( xml && node.nodeName == "#comment" ) return "\n"; var tag=""; var children=""; tag+=(prefix + "<" + node.nodeName); var attributes = node.attributes; if ( attributes && attributes.length ) { var item, name, value; for ( var index = 0; index < attributes.length; index++ ) { item = attributes.item(index); name = item.nodeName; value = item.nodeValue; if ( (name == 'lazycontent' && value == 'true') || (name == 'xulcontentsgenerated' && value == 'true') || (!xml && name == 'id') || (name == 'instanceOf') ) { // ignore these } else { tag+=(" " + name + "=\"" + value + "\""); } } } if (!xml && node.nodeType == 1 ) { // id var text = node.getAttribute('id'); if ( text && text[0] != '$' ) tag+=(" id=\"" + text + "\""); } if ( !xml && node.nodeName == "#text" ) tag+=(" = \"" + node.data + "\""); // dump IFRAME && FRAME DOM if ( node.nodeName == "IFRAME" || node.nodeName == "FRAME" ) { if ( node.name ) { var wind = top.frames[node.name]; if ( wind && wind.document && wind.document.documentElement ) { children+=(prefix + "\n"); children+=DumpNodeAndChildren(wind.document.documentElement, prefix + " ", xml); children+=(prefix + "\n"); } } } // children of nodes (other than frames) else if ( node.childNodes ) { for ( var child = 0; child < node.childNodes.length; child++ ) children+=DumpNodeAndChildren(node.childNodes[child], prefix + " ", xml); } return (xml==2&&!child)?(tag + "/>\n"):(tag + ">\n" + children + prefix + "" + node.nodeName + ">\n"); } function getProperties(obj) { var properties = ""; var propVal = ""; properties += 'Property\t\tValue\n'; for (var propName in obj) { try { propVal=obj[propName]; } catch (e) {} properties +=propName+"\t"+propVal+"\n"; } properties +="\n"; return properties; } function getPropertiesAsHTML(obj) { var properties = ""; properties = '
Property | Value |
---|---|
"+propName+" | "+obj[propName]+" |