I use the functionality that comes from implementing the code below to observe the current state of my DOM tree:
- ////////////////////////////////////////////////////////////////////
- // function walk(iBranch) //
- // Version: //
- // Description: //
- ////////////////////////////////////////////////////////////////////
- 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) {
- var strBreak, strSpacer;
- strSpacer = " ";
- if (iBranch.nodeName == "#text") {
strBreak = "";
} else {
strBreak = "<br/>";
}
- // iBrowserView.addContent(iBranch.nodeName + "<br/>");
- if (!iIndentLevel) { iIndentLevel = 0; }
// var iString = repeat(" ", iIndentLevel);
var iString = repeat(strSpacer, iIndentLevel);
var result = iString + "<" + iBranch.nodeName;
var a = iBranch.attributes; // Adding Attributes
if (a) {
for (var i=0; i < a.length; i++) {
result += " " + a[i].name + "="" + a[i].value + """;
}
}
result += ">" + strBreak;
var c = iBranch.firstChild; // Adding Children
while (c) {
result += convertXmlToHtml(c, iIndentLevel + 1, iBrowserView);
c = c.nextSibling;
}
- if (iBranch.nodeValue) { // Adding Value
var strInnerBreak;
- // Current Development
if (iBranch.nodeName == "#text") {
strInnerBreak = "";
iString = ""; // This makes the #text text flush
} else {
strInnerBreak = "<br/>";
}
- result += iString + iBranch.nodeValue + strInnerBreak;
}
result += iString + "</" + iBranch.nodeName + ">" + "<br/>";
return result;
}
-
- ////////////////////////////////////////////////////////////////////
// //
// 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.