1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// formats XML into a multi-lined, indented format
// a good toString replacement for XML with ignoreWhite = true
XMLNode.prototype.format = function(indent){
if (indent == undefined) indent = "";
var str = "";
var currNode = this.firstChild;
do{
if (currNode.hasChildNodes()){
str += indent + currNode.cloneNode(0).toString().slice(0,-3) + ">\n";
str += currNode.format(indent+"\t");
str += indent + "</" + currNode.nodeName + ">\n";
}else{
str += indent + currNode.toString() + "\n";
}
}while (currNode = currNode.nextSibling);
return str;
}