// Beyond HTML
// (c) Michael Floyd
// Web Techniques, August 1998

function displayTree(docObject, N)
{
    var child;
    var i, length;
    var indentStr;
    var A, Attr, AttrList;

    // Guarantee a document object exists
    if (docObject == null)   
    {
       alert("No Document Object for this file!");
       BrowserWin = Page;              
    }

    // Indent string for displaying child nodes
    indentStr = "";
    for (i = 1; i <= N; i++)
       indentStr = indentStr + "  ";
    
    // Get the number of child elements 
    if (docObject.children != null) 
       length = docObject.children.length;
    else
       length = 0;
    
//  Display the element information, indenting child nodes.

//  Only display elements
    if (docObject.type == 0)         
    {
       Page.writeln(indentStr, "=====");
       Page.writeln(indentStr, "Element Type: ", 
GetTypeStr(docObject.type));
       Page.writeln(indentStr, "Tag Name: ", docObject.tagName);

//  This only looks for "ID" attributes
       Attr = docObject.getAttribute("ID");    
       Page.writeln(indentStr, "Attribute: ", Attr);

       Page.writeln(indentStr, "Number of Children: ", length);
//  skip text for root node
       if (docObject.parent != null)           
          Page.writeln(indentStr, "Text: ", docObject.text);
       Page.writeln(indentStr, "=====<BR>");
     }

// If the element has children, call displayTree recursively
    if (docObject.children != null)
    {

          for (i = 0; i < docObject.children.length; i++)
        {
            if (N = length)
               N = N + 1;
            child = docObject.children.item(i);
            displayTree(child, N);
        }
    }
}

function GetTypeStr(type)
{

  if (type == 0)
    return "ELEMENT";

  if (type == 1)
    return "TEXT";

  if (type == 2)
    return "COMMENT";

  if (type == 3)
    return "DOCUMENT";

  if (type == 4)
    return "DTD";
  else
    return "OTHER";
}