Recursive XML walk finding empty nodes



Using the following function



var data = [];
function recurseXML(node, path) {
var i, nodes;
if (node.hasChildNodes()) {
nodes = node.childNodes;
path += (path ? "." : "") + node.tagName
if (nodes.length < 2) {
recurseXML(nodes[0], path);
} else {
for (i = 0; i < nodes.length; i += 1) {
recurseXML(nodes[i], path + "[" + i + "]");
}
}
} else {
data.push(path + " " + (node.nodeValue).trim());
}
}


When I try to walk the XML in this fiddle it outputs as though there are empty nodes, yet there isn't


What's causing this, and how can I fix it?


No comments:

Post a Comment