dom/xslt/tests/buster/DumpDOM.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/tests/buster/DumpDOM.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +// ----------------------
     1.5 +// DumpDOM(node)
     1.6 +//
     1.7 +// Call this function to dump the contents of the DOM starting at the specified node.
     1.8 +// Use node = document.documentElement to dump every element of the current document.
     1.9 +// Use node = top.window.document.documentElement to dump every element.
    1.10 +//
    1.11 +// 8-13-99 Updated to dump almost all attributes of every node.  There are still some attributes
    1.12 +//         that are purposely skipped to make it more readable.
    1.13 +// ----------------------
    1.14 +function DumpDOM(node)
    1.15 +{
    1.16 +	dump("--------------------- DumpDOM ---------------------\n");
    1.17 +	
    1.18 +	DumpNodeAndChildren(node, "");
    1.19 +	
    1.20 +	dump("------------------- End DumpDOM -------------------\n");
    1.21 +}
    1.22 +
    1.23 +
    1.24 +// This function does the work of DumpDOM by recursively calling itself to explore the tree
    1.25 +function DumpNodeAndChildren(node, prefix)
    1.26 +{
    1.27 +	dump(prefix + "<" + node.nodeName);
    1.28 +
    1.29 +	var attributes = node.attributes;
    1.30 +	
    1.31 +	if ( attributes && attributes.length )
    1.32 +	{
    1.33 +		var item, name, value;
    1.34 +		
    1.35 +		for ( var index = 0; index < attributes.length; index++ )
    1.36 +		{
    1.37 +			item = attributes.item(index);
    1.38 +			name = item.nodeName;
    1.39 +			value = item.nodeValue;
    1.40 +			
    1.41 +			if ( (name == 'lazycontent' && value == 'true') ||
    1.42 +				 (name == 'xulcontentsgenerated' && value == 'true') ||
    1.43 +				 (name == 'id') ||
    1.44 +				 (name == 'instanceOf') )
    1.45 +			{
    1.46 +				// ignore these
    1.47 +			}
    1.48 +			else
    1.49 +			{
    1.50 +				dump(" " + name + "=\"" + value + "\"");
    1.51 +			}
    1.52 +		}
    1.53 +	}
    1.54 +	
    1.55 +	if ( node.nodeType == 1 )
    1.56 +	{
    1.57 +		// id
    1.58 +		var text = node.getAttribute('id');
    1.59 +		if ( text && text[0] != '$' )
    1.60 +			dump(" id=\"" + text + "\"");
    1.61 +	}
    1.62 +	
    1.63 +	if ( node.nodeType == Node.TEXT_NODE )
    1.64 +		dump(" = \"" + node.data + "\"");
    1.65 +	
    1.66 +	dump(">\n");
    1.67 +	
    1.68 +	// dump IFRAME && FRAME DOM
    1.69 +	if ( node.nodeName == "IFRAME" || node.nodeName == "FRAME" )
    1.70 +	{
    1.71 +		if ( node.name )
    1.72 +		{
    1.73 +			var wind = top.frames[node.name];
    1.74 +			if ( wind && wind.document && wind.document.documentElement )
    1.75 +			{
    1.76 +				dump(prefix + "----------- " + node.nodeName + " -----------\n");
    1.77 +				DumpNodeAndChildren(wind.document.documentElement, prefix + "  ");
    1.78 +				dump(prefix + "--------- End " + node.nodeName + " ---------\n");
    1.79 +			}
    1.80 +		}
    1.81 +	}
    1.82 +	// children of nodes (other than frames)
    1.83 +	else if ( node.childNodes )
    1.84 +	{
    1.85 +		for ( var child = 0; child < node.childNodes.length; child++ )
    1.86 +			DumpNodeAndChildren(node.childNodes[child], prefix + "  ");
    1.87 +	} 
    1.88 +}

mercurial