Hello; I'm trying to do extract all the information contained within an XML element so I can put it into a dynamic web page. The best way I could think of to do this is using a recursive function. So here's what I've got so far:
Code:
function recParse(node) {
s = "";
n = node.firstChild;
// alert(n);
while (n != null) {
s += n.nodeValue;
s += recParse(n);
n = n.nextSibling;
}
return s;
}
It would seem to me that this would do exactly what I need, except it doesn't. The test data I'm using is something like this:
Code:
<text>This is some text <code>with a code element</code> inside of it.</text>
When it goes to pick up the code element (that's the text element's first child), Firefox tells me for the line n.nodeValue that "n has no properties". When I uncomment that alert line, the warning box says "null"; I'm assuming that means n == null. But that can't be the case because it's passing through the while() condition and trying to execute n.nodeValue. So I'm fairly confused. JavaScript is not my forte, so any help anybody can offer will be greatly appreciated. Or if there's a less complicated way to do this, that'd be even better.
Essentially, I need to take the entirety of that text element above, and put it inside a span element. As always, thanks a bunch.