Walk the DOM

Walk the DOM

I use the functionality that comes from implementing the code below to observe the current state of my DOM tree:

  1. ////////////////////////////////////////////////////////////////////
  2. // function walk(iBranch)                            //
  3. // Version:                                                  //
  4. // Description:                                            //
  5. ////////////////////////////////////////////////////////////////////
  6. function walk(iBranch, iHtml) {
     
            var walkBrowser    = new BrowserView("Walk Results", iHtml + "<br/><br/>");
            var btnClickResult = convertXmlToHtml(iBranch, 0, walkBrowser);
     
            walkBrowser.addContent(btnClickResult + "<br/>"); // Browser Output
     
            return btnClickResult;
     
    }
     
    function convertXmlToHtml(iBranch, iIndentLevel, iBrowserView) {
  7.  var strBreak, strSpacer;
  8.  strSpacer = "&nbsp;&nbsp;&nbsp;&nbsp;";
  9.  if (iBranch.nodeName == "#text") {
     
      strBreak  = "";
     
     } else {
     
      strBreak  = "<br/>";
     
     }
  10.  // iBrowserView.addContent(iBranch.nodeName + "<br/>");
  11.  if (!iIndentLevel) { iIndentLevel = 0; }
     
     // var iString = repeat("&nbsp;&nbsp;&nbsp;&nbsp;", iIndentLevel);
     var iString = repeat(strSpacer, iIndentLevel);
     
     var result  = iString + "&lt;" + iBranch.nodeName;
     
     var a = iBranch.attributes; // Adding Attributes
     
     if (a) {
     
      for (var i=0; i < a.length; i++) {
      
       result += " " + a[i].name + "=&quot;" + a[i].value + "&quot;";
       
      }
      
     }
     
     result += "&gt;" + strBreak;
     
     var c = iBranch.firstChild; // Adding Children
     
     while (c) {
     
      result += convertXmlToHtml(c, iIndentLevel + 1, iBrowserView);
      
      c = c.nextSibling;
      
     }
  12.  if (iBranch.nodeValue) { // Adding Value
     
      var strInnerBreak;
  13.   // Current Development
      if (iBranch.nodeName == "#text") {
     
       strInnerBreak  = "";
       iString        = ""; // This makes the #text text flush
     
      } else {
     
       strInnerBreak  = "<br/>";
     
      }
  14.   result += iString + iBranch.nodeValue + strInnerBreak;
      
     }
     
     result += iString + "&lt;/" + iBranch.nodeName + "&gt;" + "<br/>";
     
     return result;
     
    }
  15.                         ////////////////////////////////////////////////////////////////////
                            //                                                                //
                            // function BrowserView(title, htmlContents)                      //
                            // Version:                                                       //
                            // Description:                                                   //
                            //                                                                //
                            ////////////////////////////////////////////////////////////////////
     
                            function BrowserView(title, htmlContents) {
                           
                                    var o = { bv: new ActiveXObject("InternetExplorer.Application") }
                                   
                                    var p = {
                                   
                                            mainObject: o,
                                            nav:        o.bv.Navigate("about: blank"),
                                            scr:        o.bv.FullScreen = false,
                                            vis:        o.bv.Visible    = true,
                                            title:      o.bv.document.title = title,
                                            content:    o.bv.document.body.innerHTML = htmlContents
                                   
                                    }
                                   
                                    p.contents = o.bv.document.body.innerHTML;
                                   
                                    p.addContent = function (contentToAdd) {
                                           
                                            o.bv.document.body.innerHTML += contentToAdd;
                                   
                                    }
                                                           
                                    return p;
                           
                            } // End of BrowserView Class //////////////////////////////////////

How do I port this JavaScript code to jQuery?  Instead of being limited to the XML DOM, I would like to use this idea for the HTML DOM as well.